![]() ![]() | ![]() |
- sorry screwed up the namespaceing of $env
1: #!/usr/bin/perl 2: # CGI-script to run LaTeX, dvips, ps2ps, ps2pdf etc. 3: # 4: # $Id: printout.pl,v 1.80 2005/05/03 22:22:47 albertel Exp $ 5: # 6: # Copyright Michigan State University Board of Trustees 7: # 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA). 9: # 10: # LON-CAPA is free software; you can redistribute it and/or modify 11: # it under the terms of the GNU General Public License as published by 12: # the Free Software Foundation; either version 2 of the License, or 13: # (at your option) any later version. 14: # 15: # LON-CAPA is distributed in the hope that it will be useful, 16: # but WITHOUT ANY WARRANTY; without even the implied warranty of 17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18: # GNU General Public License for more details. 19: # 20: # You should have received a copy of the GNU General Public License 21: # along with LON-CAPA; if not, write to the Free Software 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23: # 24: # /home/httpd/html/adm/gpl.txt 25: # 26: # http://www.lon-capa.org/ 27: # 28: 29: use lib '/home/httpd/lib/perl'; 30: use LONCAPA::loncgi; 31: use File::Path; 32: use IO::File; 33: use Image::Magick; 34: use Apache::lonhtmlcommon; 35: use Apache::lonnet; 36: use Apache::loncommon; 37: use Apache::lonlocal; 38: use Apache::lonmsg; 39: use LONCAPA::Enrollment; 40: 41: use strict; 42: 43: # Get the list of course coordinators authorized on this course: 44: #Parameters: 45: # id - Course id. 46: # dom - Domain of course. 47: #Returns: 48: # A (possibly empty) list of course coordinators. Each course coordinator 49: # is given as user:domain 50: # 51: sub get_cc_list { 52: my ($id, $dom) = @_; 53: my @personel = &Apache::lonnet::getkeys('nohist_userroles', $dom, $id); 54: my @coordinators; 55: foreach my $person (@personel) { 56: my @info = split(/:/, $person); 57: my $role = $info[0]; 58: my $user = $info[1]; 59: my $udom = $info[2]; 60: if ($role eq 'cc') { 61: my $isactive = &LONCAPA::Enrollment::check_user_status($udom, $user, $dom, $id, 'cc'); 62: if ($isactive eq 'ok') { 63: push @coordinators, $user.':'.$udom; 64: } 65: } 66: } 67: return (@coordinators); 68: } 69: # 70: # Determine if a user is operating as a student for this course/domain. 71: # 72: # 73: #Parameters: 74: # course - The course id. 75: # cdom - The course domain. 76: # 77: #Implicit: 78: # $env{request.role} contains the role under which this user operated this 79: # this request. 80: sub is_student { 81: my ($course, $cdom) = @_; 82: my $active_role = $env{'request.role'}; 83: my @role_fields = split(/\//, $active_role); 84: 85: 86: if ( ($role_fields[0] eq 'st.') && ($role_fields[1] eq $cdom) && 87: ($role_fields[2] eq $course)) { 88: return 1; 89: } else { 90: return 0; 91: } 92: 93: 94: } 95: 96: # 97: # Debugging: Dump the environment for debugging. 98: # 99: sub dumpenv { 100: print "<p>-------------------</p>"; 101: foreach my $key (sort (keys %env)) { 102: print "<br />$key -> $env{$key}"; 103: } 104: print "<p>-------------------</p>"; 105: } 106: 107: # 108: # This sub sends a message to the appropriate person if there was an error 109: # rendering the latex At present, there's only one case to consider: 110: # a student printing inside a course results in messages to the course coordinator. 111: #Parmaeters: 112: # identifier - The unique identifier of this cgi request. 113: # logfile - The contents of the log file (included in the message). 114: # texfile - reference to an array containing the LaTeX input file 115: # (included in the message). 116: #Implicit inputs: 117: # From the environment: 118: # cgi.$identifier.user - User doing the printing. 119: # cgi.$identifier.domain - Domain the user is logged in on with printing. 120: # cgi.$identifier.courseid - Id of the course (if this is a course). 121: # cgi.$identifier.coursedom- Domain in which course was constituted. 122: # cgi.$identifier.resources - List of resource URL's for which the print 123: # was attempted. 124: # 125: sub send_error_mail { 126: my ($identifier,$logfile, $texfile) = @_; 127: my $user = $env{"cgi.$identifier.user"}; 128: my $domain = $env{"cgi.$identifier.domain"}; 129: my $courseid = $env{"cgi.$identifier.courseid"}; 130: my $coursedom= $env{"cgi.$identifier.coursedom"}; 131: my $resources= $env{"cgi.$identifier.resources"}; 132: 133: # &dumpenv(); 134: 135: 136: 137: # Only continue if there is a user, domain, courseid, course domain 138: # and resources: 139: 140: if(defined($user) && defined($domain) && defined($courseid) && 141: defined($coursedom) && defined($resources) ){ 142: 143: my @cclist = &get_cc_list($courseid, $coursedom); 144: 145: # Only mail if the conditions are ripe for it: 146: # The user is a student in the course: 147: # 148: 149: if (&is_student( $courseid, $coursedom)) { 150: # build the subject and message body: 151: print "sending message to course coordinators.<br />"; 152: 153: my $subject = "Print failed for $user".'@'.$domain; 154: my $message .= "Print failed to render LaTeX for $user".'@'."$domain\n"; 155: $message .= " User was attempting to print: \n"; 156: $message .= " $resources\n"; 157: $message .= "--------------------LaTeX logfile:------------ \n"; 158: $message .= $logfile; 159: $message .= "-----------------LaTeX source file: ------------\n"; 160: 161: foreach my $line (@$texfile) { 162: $message .= "$line\n"; 163: } 164: foreach my $dest (@cclist) { 165: my @destinfo = split(/:/,$dest); 166: my $user = $destinfo[0]; 167: my $dom = $destinfo[1]; 168: 169: &Apache::lonmsg::user_normal_msg($user, $dom, 170: $subject, $message); 171: 172: # No point in looking at the return status as there's no good 173: # error action I can think of right now (log maybe?). 174: } 175: } 176: } 177: } 178: 179: $|=1; 180: if (! &LONCAPA::loncgi::check_cookie_and_load_env()) { 181: print <<END; 182: Content-type: text/html 183: 184: <html> 185: <head><title>Bad Cookie</title></head> 186: <body> 187: Your cookie information is incorrect. 188: </body> 189: </html> 190: END 191: return; 192: } 193: &Apache::lonlocal::get_language_handle(); 194: &Apache::loncommon::content_type(undef,'text/html'); 195: my $bodytag=&Apache::loncommon::bodytag('Creating PDF','',''); 196: print $bodytag; 197: 198: my $identifier = $ENV{'QUERY_STRING'}; 199: my $texfile = $env{'cgi.'.$identifier.'.file'}; 200: my $laystyle = $env{'cgi.'.$identifier.'.layout'}; 201: my $numberofcolumns = $env{'cgi.'.$identifier.'.numcol'}; 202: my $paper = $env{'cgi.'.$identifier.'.paper'}; 203: my $selectionmade = $env{'cgi.'.$identifier.'.selection'}; 204: my $tableofcontents = $env{'cgi.'.$identifier.'.tableofcontents'}; 205: my $tableofindex = $env{'cgi.'.$identifier.'.tableofindex'}; 206: my $advanced_role = $env{'cgi.'.$identifier.'.role'}; 207: my $number_of_files = $env{'cgi.'.$identifier.'.numberoffiles'}+1; 208: my $student_names = $env{'cgi.'.$identifier.'.studentnames'}; 209: my $backref = &Apache::lonnet::unescape($env{'cgi.'.$identifier.'.backref'}); 210: 211: 212: my $adv = $env{'request.role.adv'}; 213: 214: my @names_pack=(); 215: if ($student_names=~/_END_/) { 216: @names_pack=split(/_ENDPERSON_/,$student_names); 217: } 218: 219: my $figfile = $texfile; 220: $figfile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.dat/; 221: my $duefile = $texfile; 222: $duefile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.due/; 223: #do we have figures? 224: # print "Figure file: $figfile\n"; 225: if (-e $figfile) { 226: # print "$figfile exists\n"; 227: my %done_conversion; 228: my $temporary_file=IO::File->new($figfile) || die "Couldn't open fig file $figfile for reading: $!\n"; 229: my @content_of_file = <$temporary_file>; 230: close $temporary_file; 231: my $noteps; 232: my %prog_state; 233: if ($adv) { %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Coverting Images to EPS','Picture Conversion Status',$#content_of_file,'inline','80'); } 234: foreach my $not_eps (@content_of_file) { 235: chomp($not_eps); 236: if ($not_eps ne '') { 237: # print "Converting $not_eps"; # Debugging. 238: my $status_statement='EPS picture for '.$not_eps; 239: # print "$status_statement\n"; 240: $not_eps=~s|\/\.\/|\/|g; 241: my $eps_f = $not_eps; 242: $eps_f =~ s/\.[^.]*$/\.eps/i; 243: if ($eps_f=~/\/home\/([^\/]+)\/public_html\//) { 244: $eps_f=~s/\/home\/([^\/]+)\/public_html/$1/; 245: $eps_f = '/home/httpd/prtspool/'.$eps_f; 246: } elsif ($eps_f=~/$Apache::lonnet::perlvar{'lonDocRoot'}\/res\//) { 247: $eps_f=~m/$Apache::lonnet::perlvar{'lonDocRoot'}\/res\/(.+)/; 248: $eps_f = '/home/httpd/prtspool/'.$1; 249: } elsif ($eps_f=~/$Apache::lonnet::perlvar{'lonUsersDir'}\//) { 250: $eps_f=~/$Apache::lonnet::perlvar{'lonUsersDir'}\/([^\/]+)\/\w\/\w\/\w\/(.+)/; 251: $eps_f = '/home/httpd/prtspool/'.$1.'/'.$2; 252: } 253: $eps_f =~ s/ /\_/g; # Spaces are problematic for system commands and LaTeX. 254: my $path=$eps_f; 255: $path =~ s/\/([^\/]+)\.eps$//; 256: # print "Final file path: $path "; # Debugging 257: File::Path::mkpath($path,0,0777); 258: $not_eps =~ s/^\s+//; 259: $not_eps =~ s/\s+$//; 260: $not_eps =~ s/ /\\ /g; 261: if ( exists($done_conversion{$not_eps})) { next; } 262: if ($adv) { 263: my $prettyname=$not_eps; 264: $prettyname=~s|/home/([^/]+)/public_html|/priv/$1|; 265: $prettyname=~s|$Apache::lonnet::perlvar{'lonDocRoot'}/|/|; 266: &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,'Converting to EPS '.$prettyname); 267: } 268: $done_conversion{$not_eps}=1; 269: # print "Converting $not_eps -> $eps_f"; # Debugging 270: system("convert $not_eps $eps_f"); 271: #check is eps exist in prtspool 272: if(not -e $eps_f) { 273: for (my $i=0;$i<10000;$i++) { 274: if (-e $eps_f.'.'.$i) { 275: rename $eps_f.'.'.$i, $eps_f; 276: last; 277: } 278: } 279: } 280: } 281: } 282: if ($adv) { 283: &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state); 284: } 285: unlink($figfile); 286: } 287: #print "$texfile\n"; #name of the tex file for debugging only 288: my @texfile=($texfile); 289: if ($number_of_files>1) { 290: @texfile=(); 291: for (my $i=1;$i<=$number_of_files;$i++) { 292: my $new_texfile=$texfile; 293: $new_texfile=~s/\.tex/_$i\.tex/; 294: push @texfile,$new_texfile; 295: } 296: } 297: 298: my $ind=-1; 299: my %prog_state; 300: print "<a href=\"$backref\"><b>Return</b></a> to last resource.<br /><br />"; 301: if ($adv) { %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Print Status','Class Print Status',$number_of_files,'inline','80'); } 302: print "<br />"; 303: foreach $texfile (@texfile) { 304: my $status_statement=''; 305: my $link_text='download PDF'; 306: $ind++; 307: my @stud_info=split(/_END_/,$names_pack[$ind]); 308: my @tempo_array=split(/:/,$stud_info[0]); 309: my $name; 310: if ($tempo_array[3]) { 311: $name=$tempo_array[3]; 312: } else { 313: $name=$tempo_array[0].'@'.$tempo_array[1]; 314: } 315: $link_text='<b>'.$name.'</b>'; 316: $status_statement.=$name; 317: if ($#stud_info>0) { 318: @tempo_array=split(/:/,$stud_info[-1]); 319: if ($tempo_array[3]) { 320: $name=$tempo_array[3]; 321: } else { 322: $name=$tempo_array[0].'@'.$tempo_array[1]; 323: } 324: $link_text.=' - <b>'.$name.'</b>'; 325: $status_statement.=' - '.$name; 326: } 327: if ($adv) { &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,'Creating PDF for '.$status_statement); } 328: if (-e $texfile) { 329: $texfile =~ m/^(.*)\/([^\/]+)$/; 330: my $name_file = $2; 331: my $path_file = $1.'/'; 332: chdir $path_file; 333: my $dvi_file= $name_file; $dvi_file =~ s/\.tex/\.dvi/; 334: &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null", 335: "for $status_statement now LaTeXing file", 336: \%prog_state,$dvi_file); 337: if ($tableofcontents eq 'yes') { 338: &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null", 339: "for $status_statement now LaTeXing file for table of contents", 340: \%prog_state,$dvi_file); 341: } #to create table of contents 342: my $idxname=$name_file; 343: $idxname=~s/\.tex$/\.idx/; 344: if ($tableofindex eq 'yes') { 345: &busy_wait_command("makeindex $idxname", 346: "making index file", 347: \%prog_state,$idxname); 348: &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null", 349: "for $status_statement now LaTeXing file for index section", 350: \%prog_state,$dvi_file); 351: } #to create index 352: #Do we have a latex error in the log file? 353: my $logfilename = $texfile; $logfilename =~ s/\.tex$/\.log/; 354: my $temporary_file=IO::File->new($logfilename) || die "Couldn't open log file $logfilename for reading: $!\n"; 355: my @content_of_file = <$temporary_file>; 356: close $temporary_file; 357: my $body_log_file = join(' ',@content_of_file); 358: $logfilename =~ s/\.log$/\.html/; 359: $temporary_file = IO::File->new('>'.$logfilename); 360: print $temporary_file '<html><head><title>LOGFILE</title></head><body><pre>'.$body_log_file.'</pre></body></html>'."\n"; 361: if ($body_log_file=~m/!\s+Emergency stop/) { 362: #LaTeX failed to parse tex file 363: print "<h2>LaTeX could not successfully parse your tex file.</h2>"; 364: print "It probably has errors in it.<br />"; 365: my $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART'; 366: my $whereitends = rindex $body_log_file,'STAMPOFPASSEDRESOURCEEND'; 367: if ($whereitbegins!=-1 and $whereitends!=-1) { 368: print "With very high probability this error occured in ".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)."<br /><br />"; 369: } 370: print "Here are the error messages in the LaTeX log file</br><br /><pre>"; 371: my $sygnal = 0; 372: for (my $i=0;$i<=$#content_of_file;$i++) { 373: if ($content_of_file[$i]=~m/^Runaway argument?/ or $content_of_file[$i]=~m/^!/) { 374: $sygnal = 1; 375: } 376: if ($content_of_file[$i]=~m/Here is how much of/) { 377: $sygnal = 0; 378: } 379: if ($sygnal) { 380: print "$content_of_file[$i]"; 381: } 382: } 383: print "</pre>\n"; 384: if ($advanced_role) { 385: print "<p> Advanced role </p>"; 386: print "<b><big>The link to "; 387: $logfilename=~s/\/home\/httpd//; 388: print "<a href=\"$logfilename\">Your log file </a></big></b>"; 389: print "\n"; 390: #link tooriginal LaTeX file (included according Michael Hamlin desire) 391: my $tex_temporary_file=IO::File->new($texfile) || die "Couldn't open tex file $texfile for reading: $!\n"; 392: my @tex_content_of_file = <$tex_temporary_file>; 393: close $tex_temporary_file; 394: my $body_tex_file = join(' ',@tex_content_of_file); 395: $texfile =~ s/\.tex$/aaaaa\.html/; 396: $tex_temporary_file = IO::File->new('>'.$texfile); 397: print $tex_temporary_file '<html><head><title>LOGFILE</title></head><body><pre>'.$body_tex_file.'</pre></body></html>'."\n"; 398: print "<br /><br />"; 399: print "<b><big>The link to "; 400: $texfile=~s/\/home\/httpd//; 401: print "<a href=\"$texfile\">Your original LaTeX file </a></big></b>"; 402: print "\n"; 403: } else { # Student role... 404: # at this point: 405: # $body_log_file - contains the log file. 406: # $name_file - is the name of the LaTeX file. 407: # $identifier - is the unique LaTeX identifier.l 408: 409: my $tex_handle = IO::File->new($name_file); 410: my @tex_contents = <$tex_handle>; 411: &send_error_mail($identifier, $body_log_file, \@tex_contents); 412: } 413: 414: } elsif ($body_log_file=~m/<inserted text>/) { 415: my $whereitbegins = index $body_log_file,'<inserted text>'; 416: print "You are running LaTeX in <b>batch mode</b>."; 417: while ($whereitbegins != -1) { 418: my $tempobegin=$whereitbegins; 419: $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART',$whereitbegins; 420: my $whereitends = index $body_log_file,'STAMPOFPASSEDRESOURCEEND',$whereitbegins; 421: print "<br />It has found an error in".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)." <br /> and corrected it.\n"; 422: print "Usually this correction is valid but you probably need to check the indicated resource one more time and implement neccessary corrections by yourself.\n"; 423: $whereitbegins = index $body_log_file,'<inserted text>',$tempobegin+10; 424: } 425: $name_file =~ s/\.tex/\.dvi/; 426: my $new_name_file = $name_file; 427: $new_name_file =~ s/\.dvi/\.ps/; 428: my $papera=$paper; 429: if ($papera eq 'letter') {$papera='';} 430: if ($papera ne '') {$papera='-t'.$papera;} 431: my $comma = "dvips $papera -Ppdf -G0 -o $new_name_file"; 432: &busy_wait_command("$comma $name_file 1>/dev/null 2>/dev/null", 433: "for $status_statement now Converting to PS", 434: \%prog_state,$new_name_file); 435: if (-e $new_name_file) { 436: print "<h1>PDF output file (see link below)</h1>\n"; 437: $new_name_file =~ m/^(.*)\./; 438: my $ps_file = my $tempo_file = $1.'temporar.ps'; 439: my $pdf_file = $1.'.pdf'; 440: if ($laystyle eq 'album' and $numberofcolumns eq '2') { 441: $comma = "psnup -2 -s1.0 $new_name_file"; 442: &busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null", 443: "for $status_statement now Modifying PS layout", 444: \%prog_state,$tempo_file); 445: } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') { 446: my $papera=$paper; 447: if ($papera eq 'letter') {$papera='';} 448: if ($papera ne '') {$papera='-p'.$papera;} 449: $comma = 'pstops '.$papera.' "2:0+1(0.48w,0)"'; 450: &busy_wait_command("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null", 451: "for $status_statement now Modifying PS layout", 452: \%prog_state,$tempo_file); 453: 454: } else { 455: $ps_file=$new_name_file; 456: } 457: &busy_wait_command("ps2pdf $ps_file $pdf_file 1>/dev/null 2>/dev/null", 458: "for $status_statement now Converting PS to PDF", 459: \%prog_state, $pdf_file); 460: 461: my $texlog = $texfile; 462: my $texaux = $texfile; 463: my $texdvi = $texfile; 464: my $texps = $texfile; 465: $texlog =~ s/\.tex/\.log/; 466: $texaux =~ s/\.tex/\.aux/; 467: $texdvi =~ s/\.tex/\.dvi/; 468: $texps =~ s/\.tex/\.ps/; 469: my @garb = ($texaux,$texdvi,$texps); 470: # unlink @garb; 471: unlink $duefile; 472: print "<a href=\"/prtspool/$pdf_file\">Your PDF document</a>"; 473: } 474: if ($advanced_role) { 475: print "<br /><br />"; 476: print "<b><big>The link to "; 477: $logfilename=~s/\/home\/httpd//; 478: print "<a href=\"$logfilename\">Your log file </a></big></b>"; 479: print "\n"; 480: #link tooriginal LaTeX file (included according Michael Hamlin desire) 481: my $tex_temporary_file=IO::File->new($texfile) || die "Couldn't open tex file $texfile for reading: $!\n"; 482: my @tex_content_of_file = <$tex_temporary_file>; 483: close $tex_temporary_file; 484: my $body_tex_file = join(' ',@tex_content_of_file); 485: $texfile =~ s/\.tex$/aaaaa\.html/; 486: $tex_temporary_file = IO::File->new('>'.$texfile); 487: print $tex_temporary_file '<html><head><title>LOGFILE</title></head><body><pre>'.$body_tex_file.'</pre></body></html>'."\n"; 488: print "<br /><br />"; 489: print "<b><big>The link to "; 490: $texfile=~s/\/home\/httpd//; 491: print "<a href=\"$texfile\">Your original LaTeX file </a></big></b>"; 492: print "\n"; 493: } 494: } else { 495: #LaTeX successfully parsed tex file 496: $name_file =~ s/\.tex/\.dvi/; 497: my $new_name_file = $name_file; 498: $new_name_file =~ s/\.dvi/\.ps/; 499: my $papera=$paper; 500: if ($papera eq 'letter') {$papera='';} 501: if ($papera ne '') {$papera='-t'.$papera;} 502: my $comma = "dvips $papera -Ppdf -G0 -o $new_name_file"; 503: &busy_wait_command("$comma $name_file 1>/dev/null 2>/dev/null", 504: "for $status_statement now Converting to PS", 505: \%prog_state,$new_name_file); 506: if (-e $new_name_file) { 507: print "<br />"; 508: $new_name_file =~ m/^(.*)\./; 509: my $ps_file = my $tempo_file = $1.'temporar.ps'; 510: my $pdf_file = $1.'.pdf'; 511: if ($laystyle eq 'album' and $numberofcolumns eq '2') { 512: $comma = "psnup -2 -s1.0 $new_name_file"; 513: &busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null", 514: "for $status_statement now Modifying PS layout", 515: \%prog_state,$tempo_file); 516: } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') { 517: $papera=~s/t/p/; 518: $comma = 'pstops '.$papera.' "2:0+1(0.48w,0)"'; 519: &busy_wait_command("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null", 520: "for $status_statement now Modifying PS layout", 521: \%prog_state,$tempo_file); 522: } else { 523: $ps_file=$new_name_file; 524: } 525: my $addtoPSfile={'legal'=>'<< /PageSize [612 1008] >> setpagedevice', 526: 'tabloid'=>'<< /PageSize [792 1224] >> setpagedevice', 527: 'executive'=>,'<< /PageSize [540 720] >> setpagedevice', 528: 'a2'=>'<< /PageSize [1195.02 1690.09] >> setpagedevice', 529: 'a3'=>'<< /PageSize [842 1195.02] >> setpagedevice', 530: 'a4'=>'<< /PageSize [595.2 842] >> setpagedevice', 531: 'a5'=>'<< /PageSize [421.1 595.2] >> setpagedevice', 532: 'a6'=>'<< /PageSize [298.75 421.1] >> setpagedevice', 533: }; 534: if ($paper ne 'letter') { 535: open(FFH,'<',$ps_file) || die "Couldn't open ps file $ps_file for reading: $!\n"; 536: my $new_ps_file='new'.$ps_file; 537: open(FFHS,'>',$new_ps_file) || die "Couldn't open new ps file $new_ps_file for reading: $!\n"; 538: print FFHS $addtoPSfile->{$paper}."\n"; 539: while (<FFH>) { 540: print FFHS $_; 541: } 542: close(FFH); 543: close(FFHS); 544: $ps_file=$new_ps_file; 545: } 546: &busy_wait_command("ps2pdf $ps_file $pdf_file 1>/dev/null 2>/dev/null", 547: "for $status_statement now Converting PS to PDF", 548: \%prog_state,$pdf_file); 549: 550: my $texlog = $texfile; 551: my $texaux = $texfile; 552: my $texdvi = $texfile; 553: my $texps = $texfile; 554: $texlog =~ s/\.tex/\.log/; 555: $texaux =~ s/\.tex/\.aux/; 556: $texdvi =~ s/\.tex/\.dvi/; 557: $texps =~ s/\.tex/\.ps/; 558: my @garb = ($texlog,$texaux,$texdvi,$texps); 559: # unlink @garb; 560: unlink $duefile; 561: print "<a href=\"/prtspool/$pdf_file\">$link_text - click here to download pdf</a>"; 562: print "\n"; 563: } 564: } 565: } else { 566: print "LaTeX file $texfile was not created successfully"; 567: } 568: } 569: print "<br />"; 570: if ($number_of_files>1) { 571: my $zipfile=$texfile[0]; 572: $zipfile=~s/\.tex/\.zip/; 573: my $statement="zip $zipfile"; 574: foreach my $file (@texfile) { 575: $file=~s/\.tex/.\pdf/; 576: $statement.=' '.$file; 577: } 578: print("<pre>Zip Output:\n"); 579: system($statement); 580: print("</pre>"); 581: $zipfile=~s/\/home\/httpd//; 582: print "<br /> A <a href=\"$zipfile\">ZIP file</a> of all the PDFs."; 583: } 584: if ($adv) { &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state); } 585: 586: my $done; 587: sub REAPER { 588: $done=1; 589: } 590: 591: sub busy_wait_command { 592: my ($command,$message,$progress_win,$output_file)=@_; 593: 594: $SIG{CHLD} = \&REAPER; 595: $done=0; 596: my $pid=open(CMD,"$command |"); 597: if ($adv) { 598: &Apache::lonhtmlcommon::Update_PrgWin('',$progress_win,$message); 599: } 600: while(!$done) { 601: sleep 1; 602: my $extra_msg; 603: if ($output_file) { 604: my $size=(stat($output_file))[7]; 605: $extra_msg=", $size bytes generated"; 606: } 607: if ($adv) { 608: &Apache::lonhtmlcommon::Update_PrgWin('',$progress_win, 609: $message.$extra_msg); 610: } 611: } 612: $SIG{CHLD}='IGNORE'; 613: close(CMD); 614: } 615: 616: 617: 618: