Annotation of loncom/interface/printout.pl, revision 1.26
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.25 www 5: print (<<ENDSCRIPT);
6: <script type="text/javascript">
7: function LONCAPAreg() {
8: swmenu=window.open('',"LCmenumsul1","",false);swmenu.windowloaded(self.name);
9: }
10:
11: function LONCAPAstale() {
12: swmenu=window.open('',"LCmenumsul1","",false);swmenu.windowunloaded(self.name);
13: }
14: </script>
15: ENDSCRIPT
1.26 ! www 16: print "<body bgcolor='#FFFFFF' onLoad='LONCAPAreg();' onUnload='LONCAPAstale()'>\n";
1.21 sakharuk 17: my ($texfile,$laystyle,$numberofcolumns,$selectionmade) = split(/&/,$ENV{'QUERY_STRING'});
1.14 sakharuk 18: my $figfile = $texfile;
19: $figfile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.dat/;
20: my $duefile = $texfile;
21: $duefile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.due/;
22: #do we have figures?
23: if (-e $figfile) {
24: my $temporary_file=IO::File->new($figfile) || die "Couldn't open file for reading: $!\n";
25: my @content_of_file = <$temporary_file>;
26: close $temporary_file;
27: my $noteps;
28: foreach $not_eps (@content_of_file) {
29: if ($not_eps ne '') {
30: my $eps_f = $not_eps;
31: $eps_f =~ s/\.[^.]*$/\.eps/i;
32: $_ = $eps_f;
33: m/\/([^\/]+)$/;
34: $eps_f = '/home/httpd/prtspool/'.$1;
35: my $image = Image::Magick->new;
36: $not_eps =~ s/^\s+//;
37: $not_eps =~ s/\s+$//;
38: $status = $image->Read($not_eps);
39: if ($status) {print " $status ";}
40: $image->Set(page => '+100+200');
41: $status = $image->Write($eps_f);
42: if ($status) {print " $status ";}
1.20 sakharuk 43: #check is eps exist in prtspool
44: if(not -e $eps_f) {
45: for (my $i=0;$i<10000;$i++) {
46: if (-e $eps_f.'.'.$i) {
47: rename $eps_f.'.'.$i, $eps_f;
48: last;
49: }
50: }
51: }
1.14 sakharuk 52: }
53: }
54: unlink $figfile;
55: }
56: #print "$texfile\n"; #name of the tex file for debugging only
57: $texfile =~ m/^(.*)\/([^\/]+)$/;
58: my $name_file = $2;
59: my $path_file = $1.'/';
60: chdir $path_file;
61: system("latex $name_file 1>/dev/null 2>/dev/null");
1.17 sakharuk 62: #Do we have a latex error in the log file?
63: my $logfilename = $texfile;
64: $logfilename =~ s/\.tex$/\.log/;
65: my $temporary_file=IO::File->new($logfilename) || die "Couldn't open file for reading: $!\n";
66: my @content_of_file = <$temporary_file>;
67: close $temporary_file;
68: my $body_log_file = join(' ',@content_of_file);
69: if ($body_log_file=~m/!\s+Emergency stop/) {
70: #LaTeX failed to parse tex file
1.22 sakharuk 71: print "<h2>LaTeX could not successfully parse your tex file.</h2>";
72: print "It probably has errors in it.<br />";
73: my $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART';
74: my $whereitends = rindex $body_log_file,'STAMPOFPASSEDRESOURCEEND';
75: if ($whereitbegins!=-1 and $whereitends!=-1) {
76: print "With very high probability this error occured in ".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)."<br /><br />";
77: }
78: print "Here are the error messages in the LaTeX log file</br><br />";
1.17 sakharuk 79: my $sygnal = 0;
80: for (my $i=0;$i<=$#content_of_file;$i++) {
1.22 sakharuk 81: if ($content_of_file[$i]=~m/^Runaway argument?/ or $content_of_file[$i]=~m/^!/) {
1.17 sakharuk 82: $sygnal = 1;
83: }
84: if ($content_of_file[$i]=~m/Here is how much of/) {
85: $sygnal = 0;
86: }
87: if ($sygnal) {
88: print "$content_of_file[$i]<br />";
89: }
90: }
91: } else {
92: #LaTeX successfully parsed tex file
93: $name_file =~ s/\.tex/\.dvi/;
1.14 sakharuk 94: my $new_name_file = $name_file;
95: $new_name_file =~ s/\.dvi/\.ps/;
1.23 albertel 96: my $comma = "dvips -Ppdf -G0 -o $new_name_file";
1.24 sakharuk 97: system("$comma $name_file 1>/dev/null 2>/dev/null");
1.17 sakharuk 98: if (-e $new_name_file) {
1.25 www 99: print "<h1>Successfully created PDF output file (click on link below)</h1>\n";
1.17 sakharuk 100: $new_name_file =~ m/^(.*)\./;
101: my $tempo_file = $1.'temporar.ps';
102: my $name_file = $1.'.pdf';
1.22 sakharuk 103: if ($laystyle eq 'album' and $numberofcolumns eq '2') {
1.17 sakharuk 104: $comma = "psnup -2 -s1.0 $new_name_file";
1.24 sakharuk 105: system("$comma $tempo_file 1>/dev/null 2>/dev/null");
106: system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
1.18 sakharuk 107: } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
1.21 sakharuk 108: $comma = 'pstops -pletter "2:0+1(0.48w,0)"';
1.24 sakharuk 109: system("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null");
110: system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
1.18 sakharuk 111: } else {
1.24 sakharuk 112: system("ps2pdf $new_name_file $name_file 1>/dev/null 2>/dev/null");
1.17 sakharuk 113: }
114: my $texlog = $texfile;
115: my $texaux = $texfile;
116: my $texdvi = $texfile;
117: my $texps = $texfile;
118: $texlog =~ s/\.tex/\.log/;
119: $texaux =~ s/\.tex/\.aux/;
120: $texdvi =~ s/\.tex/\.dvi/;
121: $texps =~ s/\.tex/\.ps/;
122: my @garb = ($texlog,$texaux,$texdvi,$texps);
1.22 sakharuk 123: # unlink @garb;
1.17 sakharuk 124: unlink $duefile;
125: print "<a href=\"/prtspool/$name_file\">Your PDF document</a>";
126: print "\n";
1.14 sakharuk 127: }
128: }
1.17 sakharuk 129:
130:
131:
1.1 sakharuk 132:
133:
134:
135:
1.4 sakharuk 136:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>