Annotation of loncom/interface/printout.pl, revision 1.19
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";
1.18 sakharuk 6: my ($texfile,$laystyle,$numberofcolumns) = split(/&/,$ENV{'QUERY_STRING'});
1.14 sakharuk 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");
1.17 sakharuk 42: #Do we have a latex error in the log file?
43: my $logfilename = $texfile;
44: $logfilename =~ s/\.tex$/\.log/;
45: my $temporary_file=IO::File->new($logfilename) || die "Couldn't open file for reading: $!\n";
46: my @content_of_file = <$temporary_file>;
47: close $temporary_file;
48: my $body_log_file = join(' ',@content_of_file);
49: if ($body_log_file=~m/!\s+Emergency stop/) {
50: #LaTeX failed to parse tex file
51: print "<h1>LaTeX could not successfully parse your tex file.</h1>";
52: print "<h2>It probably has errors in it.</h2>";
53: print "Here are the error messages in the LaTeX log file</br>";
54: my $sygnal = 0;
55: for (my $i=0;$i<=$#content_of_file;$i++) {
56: if ($content_of_file[$i]=~m/^!/) {
57: $sygnal = 1;
58: }
59: if ($content_of_file[$i]=~m/Here is how much of/) {
60: $sygnal = 0;
61: }
62: if ($sygnal) {
63: print "$content_of_file[$i]<br />";
64: }
65: }
66: } else {
67: #LaTeX successfully parsed tex file
68: $name_file =~ s/\.tex/\.dvi/;
1.14 sakharuk 69: my $new_name_file = $name_file;
70: $new_name_file =~ s/\.dvi/\.ps/;
71: my $comma = "dvips -o $new_name_file";
72: system("$comma $name_file");
1.17 sakharuk 73: if (-e $new_name_file) {
74: print "<h1>OUTPUT is in the PDF FILE (see link below)</h1>\n";
75: $new_name_file =~ m/^(.*)\./;
76: my $tempo_file = $1.'temporar.ps';
77: my $name_file = $1.'.pdf';
78: if ($laystyle eq 'album') {
79: $comma = "psnup -2 -s1.0 $new_name_file";
80: system("$comma $tempo_file");
81: system("ps2pdf $tempo_file $name_file");
1.18 sakharuk 82: } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
1.19 ! albertel 83: $comma = 'pstops -pletter "2:0+1(0.5w,0)"';
1.18 sakharuk 84: system("$comma $new_name_file $tempo_file");
85: system("ps2pdf $tempo_file $name_file");
86: } else {
1.17 sakharuk 87: system("ps2pdf $new_name_file $name_file");
88: }
89: my $texlog = $texfile;
90: my $texaux = $texfile;
91: my $texdvi = $texfile;
92: my $texps = $texfile;
93: $texlog =~ s/\.tex/\.log/;
94: $texaux =~ s/\.tex/\.aux/;
95: $texdvi =~ s/\.tex/\.dvi/;
96: $texps =~ s/\.tex/\.ps/;
97: my @garb = ($texlog,$texaux,$texdvi,$texps);
1.18 sakharuk 98: #unlink @garb;
1.17 sakharuk 99: unlink $duefile;
100: print "<a href=\"/prtspool/$name_file\">Your PDF document</a>";
101: print "\n";
1.14 sakharuk 102: }
103: }
1.17 sakharuk 104:
105:
106:
1.1 sakharuk 107:
108:
109:
110:
1.4 sakharuk 111:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>