Annotation of loncom/interface/printout.pl, revision 1.28
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";
1.27 www 5: print "<body bgcolor=\"#FFFFFF\">\n";
1.21 sakharuk 6: my ($texfile,$laystyle,$numberofcolumns,$selectionmade) = 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
1.22 sakharuk 60: print "<h2>LaTeX could not successfully parse your tex file.</h2>";
61: print "It probably has errors in it.<br />";
62: my $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART';
63: my $whereitends = rindex $body_log_file,'STAMPOFPASSEDRESOURCEEND';
64: if ($whereitbegins!=-1 and $whereitends!=-1) {
65: print "With very high probability this error occured in ".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)."<br /><br />";
66: }
67: print "Here are the error messages in the LaTeX log file</br><br />";
1.17 sakharuk 68: my $sygnal = 0;
69: for (my $i=0;$i<=$#content_of_file;$i++) {
1.22 sakharuk 70: if ($content_of_file[$i]=~m/^Runaway argument?/ or $content_of_file[$i]=~m/^!/) {
1.17 sakharuk 71: $sygnal = 1;
72: }
73: if ($content_of_file[$i]=~m/Here is how much of/) {
74: $sygnal = 0;
75: }
76: if ($sygnal) {
77: print "$content_of_file[$i]<br />";
78: }
79: }
80: } else {
81: #LaTeX successfully parsed tex file
82: $name_file =~ s/\.tex/\.dvi/;
1.14 sakharuk 83: my $new_name_file = $name_file;
84: $new_name_file =~ s/\.dvi/\.ps/;
1.23 albertel 85: my $comma = "dvips -Ppdf -G0 -o $new_name_file";
1.24 sakharuk 86: system("$comma $name_file 1>/dev/null 2>/dev/null");
1.17 sakharuk 87: if (-e $new_name_file) {
1.28 ! www 88: print "<h1>Successfully created PDF output file (see link below)</h1>\n";
1.17 sakharuk 89: $new_name_file =~ m/^(.*)\./;
90: my $tempo_file = $1.'temporar.ps';
91: my $name_file = $1.'.pdf';
1.22 sakharuk 92: if ($laystyle eq 'album' and $numberofcolumns eq '2') {
1.17 sakharuk 93: $comma = "psnup -2 -s1.0 $new_name_file";
1.24 sakharuk 94: system("$comma $tempo_file 1>/dev/null 2>/dev/null");
95: system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
1.18 sakharuk 96: } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
1.21 sakharuk 97: $comma = 'pstops -pletter "2:0+1(0.48w,0)"';
1.24 sakharuk 98: system("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null");
99: system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
1.18 sakharuk 100: } else {
1.24 sakharuk 101: system("ps2pdf $new_name_file $name_file 1>/dev/null 2>/dev/null");
1.17 sakharuk 102: }
103: my $texlog = $texfile;
104: my $texaux = $texfile;
105: my $texdvi = $texfile;
106: my $texps = $texfile;
107: $texlog =~ s/\.tex/\.log/;
108: $texaux =~ s/\.tex/\.aux/;
109: $texdvi =~ s/\.tex/\.dvi/;
110: $texps =~ s/\.tex/\.ps/;
111: my @garb = ($texlog,$texaux,$texdvi,$texps);
1.22 sakharuk 112: # unlink @garb;
1.17 sakharuk 113: unlink $duefile;
114: print "<a href=\"/prtspool/$name_file\">Your PDF document</a>";
115: print "\n";
1.14 sakharuk 116: }
117: }
1.17 sakharuk 118:
119:
120:
1.1 sakharuk 121:
122:
123:
124:
1.4 sakharuk 125:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>