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