Annotation of loncom/interface/printout.pl, revision 1.16
1.1 sakharuk 1: #!/usr/bin/perl
1.6 sakharuk 2: use IO::File;
1.7 sakharuk 3: use Image::Magick;
1.14 sakharuk 4: print "Content-type: text/html\n\n";
5: print "<body bgcolor=\"#FFFFFF\">\n";
6: my ($texfile,$laystyle) = split(/&/,$ENV{'QUERY_STRING'});
7: my $figfile = $texfile;
8: $figfile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.dat/;
9: my $duefile = $texfile;
10: $duefile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.due/;
11: #do we have figures?
12: if (-e $figfile) {
13: my $temporary_file=IO::File->new($figfile) || die "Couldn't open file for reading: $!\n";
14: my @content_of_file = <$temporary_file>;
15: close $temporary_file;
16: my $noteps;
17: foreach $not_eps (@content_of_file) {
18: if ($not_eps ne '') {
19: my $eps_f = $not_eps;
20: $eps_f =~ s/\.[^.]*$/\.eps/i;
21: $_ = $eps_f;
22: m/\/([^\/]+)$/;
23: $eps_f = '/home/httpd/prtspool/'.$1;
24: my $image = Image::Magick->new;
25: $not_eps =~ s/^\s+//;
26: $not_eps =~ s/\s+$//;
27: $status = $image->Read($not_eps);
28: if ($status) {print " $status ";}
29: $image->Set(page => '+100+200');
30: $status = $image->Write($eps_f);
31: if ($status) {print " $status ";}
32: }
33: }
34: unlink $figfile;
35: }
36: #print "$texfile\n"; #name of the tex file for debugging only
37: $texfile =~ m/^(.*)\/([^\/]+)$/;
38: my $name_file = $2;
39: my $path_file = $1.'/';
40: chdir $path_file;
41: system("latex $name_file 1>/dev/null 2>/dev/null");
42: $name_file =~ s/\.tex/\.dvi/;
43: if (-e $name_file) {
44: #if dvi file exist = LaTeX successfully parsed tex file
45: print "<h1>OUTPUT is in the PDF FILE (see link below)</h1>\n";
46: my $new_name_file = $name_file;
47: $new_name_file =~ s/\.dvi/\.ps/;
48: my $comma = "dvips -o $new_name_file";
49: system("$comma $name_file");
50: $_ = $new_name_file;
51: m/^(.*)\./;
52: my $tempo_file = $1.'temporar.ps';
53: my $name_file = $1.'.pdf';
54: if ($laystyle eq 'album') {
55: $comma = "psnup -2 -s1.0 $new_name_file";
56: system("$comma $tempo_file");
57: system("ps2pdf $tempo_file $name_file");
58: } elsif ($laystyle eq 'book') {
59: system("ps2pdf $new_name_file $name_file");
60: }
61: my $texlog = $texfile;
62: my $texaux = $texfile;
63: my $texdvi = $texfile;
64: my $texps = $texfile;
65: $texlog =~ s/\.tex/\.log/;
66: $texaux =~ s/\.tex/\.aux/;
67: $texdvi =~ s/\.tex/\.dvi/;
68: $texps =~ s/\.tex/\.ps/;
69: my @garb = ($texlog,$texaux,$texdvi,$texps);
70: unlink @garb;
71: unlink $duefile;
72: print "<a href=\"/prtspool/$name_file\">Your PDF document</a>";
73: print "\n";
74: } else {
75: print "<h1>LaTeX could not successfully parse your tex file.</h1>";
1.15 albertel 76: print "<h2>It probably has errors in it.</h2>";
1.14 sakharuk 77: my $logfilename = $texfile;
78: $logfilename =~ s/\.tex$/\.log/;
79: if (-e $logfilename) {
80: #if dvi file does not exist = LaTeX failed to parse tex file
1.16 ! matthew 81: print "Here are the error messages in the LaTeX log file</br>";
1.14 sakharuk 82: my $temporary_file=IO::File->new($logfilename) || die "Couldn't open file for reading: $!\n";
83: my @content_of_file = <$temporary_file>;
84: close $temporary_file;
85: my $sygnal = 0;
86: for (my $i=0;$i<=$#content_of_file;$i++) {
87: if ($content_of_file[$i]=~m/^!/) {
88: $sygnal = 1;
89: }
90: if ($content_of_file[$i]=~m/Here is how much of/) {
91: $sygnal = 0;
92: }
93: if ($sygnal) {
94: print "$content_of_file[$i]<br />";
95: }
96:
97: }
98: # my $content_file_string = join(' ',@content_of_file);
99:
100: # print "$content_file_string\n";
101: }
102: }
1.1 sakharuk 103:
104:
105:
106:
1.4 sakharuk 107:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>