Annotation of loncom/interface/printout.pl, revision 1.76

1.1       sakharuk    1: #!/usr/bin/perl
1.37      albertel    2: # CGI-script to run LaTeX, dvips, ps2ps, ps2pdf etc.
                      3: #
1.76    ! albertel    4: # $Id: printout.pl,v 1.75 2005/03/23 22:37:46 albertel Exp $
1.37      albertel    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: 
1.39      sakharuk   29: use lib '/home/httpd/lib/perl';
1.76    ! albertel   30: use LONCAPA::loncgi;
1.38      sakharuk   31: use File::Path;
1.6       sakharuk   32: use IO::File;
1.7       sakharuk   33: use Image::Magick;
1.47      sakharuk   34: use Apache::lonhtmlcommon;
1.71      albertel   35: use Apache::lonnet();
1.51      albertel   36: use Apache::loncommon;
                     37: use Apache::lonlocal;
1.47      sakharuk   38: 
1.59      albertel   39: use strict;
1.49      albertel   40: $|=1;
1.39      sakharuk   41: if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {
                     42:     print <<END;
                     43: Content-type: text/html
                     44: 
                     45: <html>
                     46: <head><title>Bad Cookie</title></head>
                     47: <body>
1.40      sakharuk   48: Your cookie information is incorrect.
1.39      sakharuk   49: </body>
                     50: </html>
                     51: END
                     52:     return;
                     53: }
1.51      albertel   54:  &Apache::lonlocal::get_language_handle();
                     55:  &Apache::loncommon::content_type(undef,'text/html');
                     56:  my $bodytag=&Apache::loncommon::bodytag('Creating PDF','','');
                     57:  print $bodytag;
1.39      sakharuk   58: 
1.40      sakharuk   59:   my $identifier = $ENV{'QUERY_STRING'};
1.76    ! albertel   60:   my $texfile = $env{'cgi.'.$identifier.'.file'};
        !            61:   my $laystyle = $env{'cgi.'.$identifier.'.layout'};
        !            62:   my $numberofcolumns = $env{'cgi.'.$identifier.'.numcol'};
        !            63:   my $paper = $env{'cgi.'.$identifier.'.paper'};
        !            64:   my $selectionmade = $env{'cgi.'.$identifier.'.selection'};
        !            65:   my $tableofcontents = $env{'cgi.'.$identifier.'tableofcontents'};
        !            66:   my $tableofindex = $env{'cgi.'.$identifier.'tableofindex'};
        !            67:   my $advanced_role = $env{'cgi.'.$identifier.'role'};
        !            68:   my $number_of_files = $env{'cgi.'.$identifier.'numberoffiles'}+1;
        !            69:   my $student_names = $env{'cgi.'.$identifier.'studentnames'};
        !            70:   my $backref = &Apache::lonnet::unescape($env{'cgi.'.$identifier.'backref'});
1.43      sakharuk   71: 
1.62      sakharuk   72: 
1.76    ! albertel   73:   my $adv = $env{'request.role.adv'};
1.49      albertel   74:   
1.44      sakharuk   75:   my @names_pack=();
                     76:   if ($student_names=~/_END_/) {  
                     77:       @names_pack=split(/_ENDPERSON_/,$student_names);
                     78:   }
1.39      sakharuk   79: 
1.14      sakharuk   80:   my $figfile = $texfile;
                     81:   $figfile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.dat/;
                     82:   my $duefile = $texfile;
                     83:   $duefile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.due/;
                     84:   #do we have figures?
1.73      foxr       85:   # print "Figure file: $figfile\n";
1.14      sakharuk   86:   if (-e $figfile) {
1.73      foxr       87:       # print "$figfile exists\n";
1.42      albertel   88:       my %done_conversion;
1.69      matthew    89:       my $temporary_file=IO::File->new($figfile) || die "Couldn't open fig file $figfile for reading: $!\n";
1.14      sakharuk   90:       my @content_of_file = <$temporary_file>;
                     91:       close $temporary_file;  
                     92:       my $noteps;
1.49      albertel   93:       my %prog_state;
1.59      albertel   94:       if ($adv) { %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Coverting Images to EPS','Picture Conversion Status',$#content_of_file,'inline','80');  }
                     95:       foreach my $not_eps (@content_of_file) {
1.49      albertel   96: 	  chomp($not_eps);
1.14      sakharuk   97: 	  if ($not_eps ne '') {
1.73      foxr       98: 	      # print "Converting $not_eps"; # Debugging.
1.44      sakharuk   99:               my $status_statement='EPS picture for '.$not_eps;
1.73      foxr      100: 	      # print "$status_statement\n";
1.41      sakharuk  101: 	      $not_eps=~s|\/\.\/|\/|g;
1.14      sakharuk  102: 	      my $eps_f = $not_eps;
                    103: 	      $eps_f =~ s/\.[^.]*$/\.eps/i;
1.41      sakharuk  104: 	      if ($eps_f=~/\/home\/([^\/]+)\/public_html\//) {
                    105:                   $eps_f=~s/\/home\/([^\/]+)\/public_html/$1/;
                    106: 		  $eps_f = '/home/httpd/prtspool/'.$eps_f;
1.58      sakharuk  107: 	      } elsif ($eps_f=~/$Apache::lonnet::perlvar{'lonDocRoot'}\/res\//) {
                    108: 		  $eps_f=~m/$Apache::lonnet::perlvar{'lonDocRoot'}\/res\/(.+)/;
1.41      sakharuk  109: 		  $eps_f = '/home/httpd/prtspool/'.$1;
1.58      sakharuk  110: 	      } elsif ($eps_f=~/$Apache::lonnet::perlvar{'lonUsersDir'}\//) {
1.57      sakharuk  111: 		  $eps_f=~/$Apache::lonnet::perlvar{'lonUsersDir'}\/([^\/]+)\/\w\/\w\/\w\/(.+)/;
1.56      sakharuk  112: 		  $eps_f = '/home/httpd/prtspool/'.$1.'/'.$2;
1.41      sakharuk  113: 	      }
1.74      foxr      114: 	      $eps_f  =~ s/ /\_/g; # Spaces are problematic for system commands and LaTeX.
1.38      sakharuk  115: 	      my $path=$eps_f;
1.74      foxr      116: 	      $path =~ s/\/([^\/]+)\.eps$//;
1.73      foxr      117: 	      # print "Final file path: $path "; # Debugging
1.38      sakharuk  118: 	      File::Path::mkpath($path,0,0777);
1.14      sakharuk  119: 	      $not_eps =~ s/^\s+//;
                    120: 	      $not_eps =~ s/\s+$//;
1.74      foxr      121: 	      $not_eps =~ s/ /\\ /g;
1.72      albertel  122: 	      if ( exists($done_conversion{$not_eps})) { next; }
1.49      albertel  123: 	      if ($adv) {
                    124: 		  my $prettyname=$not_eps;
                    125: 		  $prettyname=~s|/home/([^/]+)/public_html|/priv/$1|;
1.58      sakharuk  126: 		  $prettyname=~s|$Apache::lonnet::perlvar{'lonDocRoot'}/|/|;
1.72      albertel  127: 		  &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,'Converting to EPS '.$prettyname);
                    128: 	      }
1.42      albertel  129: 	      $done_conversion{$not_eps}=1;
1.73      foxr      130: 	      # print "Converting $not_eps -> $eps_f"; # Debugging
1.72      albertel  131: 	      system("convert $not_eps $eps_f");
1.20      sakharuk  132:               #check is eps exist in prtspool
                    133:               if(not -e $eps_f) {
                    134: 		  for (my $i=0;$i<10000;$i++) {
                    135: 		      if (-e $eps_f.'.'.$i) {
                    136: 			  rename $eps_f.'.'.$i, $eps_f;
                    137: 			  last;
                    138: 		      }
                    139: 		  }
                    140: 	      }  
1.14      sakharuk  141: 	  }
                    142:       }
1.74      foxr      143:       if ($adv) { 
                    144: 	  &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state); 
                    145:       }
1.52      albertel  146:       unlink($figfile);
1.14      sakharuk  147:   }
1.43      sakharuk  148:   #print "$texfile\n"; #name of the tex file for debugging only   
                    149:   my @texfile=($texfile);
                    150:   if ($number_of_files>1) {
1.49      albertel  151:       @texfile=();
                    152:       for (my $i=1;$i<=$number_of_files;$i++) {
1.43      sakharuk  153: 	  my $new_texfile=$texfile;
1.49      albertel  154: 	  $new_texfile=~s/\.tex/_$i\.tex/;
1.43      sakharuk  155: 	  push @texfile,$new_texfile;
                    156:       } 
                    157:   }
1.49      albertel  158: 
1.44      sakharuk  159: my $ind=-1;
1.49      albertel  160: my %prog_state;
1.61      albertel  161: print "<a href=\"$backref\"><b>Return</b></a> to last resource.<br /><br />";
1.59      albertel  162: if ($adv) { %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Print Status','Class Print Status',$number_of_files,'inline','80'); }
1.61      albertel  163: print "<br />";
1.43      sakharuk  164: foreach $texfile (@texfile) {
1.49      albertel  165:   my $status_statement='';
                    166:   my $link_text='download PDF';
                    167:   $ind++;
                    168:   my @stud_info=split(/_END_/,$names_pack[$ind]);
                    169:   my @tempo_array=split(/:/,$stud_info[0]);
                    170:   my $name;
                    171:   if ($tempo_array[3]) {
                    172:       $name=$tempo_array[3];
                    173:   } else {
                    174:       $name=$tempo_array[0].'@'.$tempo_array[1];
                    175:   }
1.61      albertel  176:   $link_text='<b>'.$name.'</b>';
1.49      albertel  177:   $status_statement.=$name;
                    178:   if ($#stud_info>0) {
                    179:       @tempo_array=split(/:/,$stud_info[-1]);
1.48      albertel  180:       if ($tempo_array[3]) {
                    181: 	  $name=$tempo_array[3];
                    182:       } else {
                    183: 	  $name=$tempo_array[0].'@'.$tempo_array[1];
                    184:       }
1.61      albertel  185:       $link_text.=' - <b>'.$name.'</b>';
1.49      albertel  186:       $status_statement.=' -  '.$name;
                    187:   } 
                    188:   if ($adv) { &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,'Creating PDF for '.$status_statement); }
1.29      sakharuk  189:   if (-e $texfile) {
                    190:       $texfile =~ m/^(.*)\/([^\/]+)$/; 
                    191:       my $name_file = $2;
                    192:       my $path_file = $1.'/';
                    193:       chdir $path_file;
1.59      albertel  194:       my $dvi_file= $name_file; $dvi_file =~ s/\.tex/\.dvi/;
                    195:       &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null",
                    196: 			 "for $status_statement now LaTeXing file",
                    197: 			 \%prog_state,$dvi_file);
1.40      sakharuk  198:       if ($tableofcontents eq 'yes') {
1.63      sakharuk  199:       &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null",
                    200: 			 "for $status_statement now LaTeXing file for table of contents",
                    201: 			 \%prog_state,$dvi_file);
1.40      sakharuk  202:       } #to create table of contents
1.33      sakharuk  203:       my $idxname=$name_file;
                    204:       $idxname=~s/\.tex$/\.idx/;
1.40      sakharuk  205:       if ($tableofindex eq 'yes') {
1.63      sakharuk  206: 	  &busy_wait_command("makeindex $idxname",
                    207: 			     "making index file",
                    208: 			     \%prog_state,$idxname);
                    209: 	  &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null",
                    210: 			     "for $status_statement now LaTeXing file for index section",
                    211: 			     \%prog_state,$dvi_file);
1.33      sakharuk  212:       } #to create index
1.29      sakharuk  213:       #Do we have a latex error in the log file?
1.67      sakharuk  214:       my $logfilename = $texfile; $logfilename =~ s/\.tex$/\.log/;
1.69      matthew   215:       my $temporary_file=IO::File->new($logfilename) || die "Couldn't open log file $logfilename for reading: $!\n";
1.29      sakharuk  216:       my @content_of_file = <$temporary_file>;
                    217:       close $temporary_file; 
1.30      sakharuk  218:       my $body_log_file = join(' ',@content_of_file);
                    219:       $logfilename =~ s/\.log$/\.html/;
                    220:       $temporary_file = IO::File->new('>'.$logfilename); 
                    221:       print $temporary_file '<html><head><title>LOGFILE</title></head><body><pre>'.$body_log_file.'</pre></body></html>'."\n";
1.29      sakharuk  222:       if ($body_log_file=~m/!\s+Emergency stop/) {
                    223: 	  #LaTeX failed to parse tex file 
                    224: 	  print "<h2>LaTeX could not successfully parse your tex file.</h2>";
                    225: 	  print "It probably has errors in it.<br />";
                    226: 	  my $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART';
                    227: 	  my $whereitends = rindex $body_log_file,'STAMPOFPASSEDRESOURCEEND';
                    228: 	  if ($whereitbegins!=-1 and $whereitends!=-1) {
1.44      sakharuk  229:  	      print "With very high probability this error occured in ".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)."<br /><br />";
1.29      sakharuk  230: 	  }
1.70      albertel  231: 	  print "Here are the error messages in the LaTeX log file</br><br /><pre>";
1.29      sakharuk  232: 	  my $sygnal = 0;
                    233: 	  for (my $i=0;$i<=$#content_of_file;$i++) {
                    234: 	      if ($content_of_file[$i]=~m/^Runaway argument?/ or $content_of_file[$i]=~m/^!/) {
                    235: 		  $sygnal = 1;
                    236: 	      } 
                    237: 	      if ($content_of_file[$i]=~m/Here is how much of/) {
                    238: 		  $sygnal = 0;
                    239: 	      } 
                    240: 	      if ($sygnal) {
1.70      albertel  241: 		  print "$content_of_file[$i]";
1.29      sakharuk  242: 	      }  
1.36      sakharuk  243: 	  }
1.70      albertel  244: 	  print "</pre>\n";
1.75      albertel  245:           if ($advanced_role) {  
1.35      sakharuk  246:               print "<b><big>The link to ";
                    247:               $logfilename=~s/\/home\/httpd//;
                    248: 	      print "<a href=\"$logfilename\">Your log file </a></big></b>";
                    249: 	      print "\n";
                    250:               #link tooriginal LaTeX file (included according Michael Hamlin desire)
1.69      matthew   251: 	      my $tex_temporary_file=IO::File->new($texfile) || die "Couldn't open tex file $texfile for reading: $!\n";
1.35      sakharuk  252: 	      my @tex_content_of_file = <$tex_temporary_file>;
                    253: 	      close $tex_temporary_file; 
                    254: 	      my $body_tex_file = join(' ',@tex_content_of_file);
                    255: 	      $texfile =~ s/\.tex$/aaaaa\.html/;
                    256: 	      $tex_temporary_file = IO::File->new('>'.$texfile); 
                    257: 	      print $tex_temporary_file '<html><head><title>LOGFILE</title></head><body><pre>'.$body_tex_file.'</pre></body></html>'."\n";
                    258: 	      print "<br /><br />";
                    259: 	      print "<b><big>The link to ";
                    260: 	      $texfile=~s/\/home\/httpd//;
                    261: 	      print "<a href=\"$texfile\">Your original LaTeX file </a></big></b>";
                    262: 	      print "\n";
1.36      sakharuk  263: 	  }
1.35      sakharuk  264: 
1.29      sakharuk  265:       } elsif ($body_log_file=~m/<inserted text>/) {
                    266: 	  my $whereitbegins = index $body_log_file,'<inserted text>';
1.59      albertel  267: 	  print "You are running LaTeX in <b>batch mode</b>.";
1.30      sakharuk  268: 	  while ($whereitbegins != -1) {
                    269: 	      my $tempobegin=$whereitbegins;
                    270: 	      $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART',$whereitbegins;
                    271: 	      my $whereitends = index $body_log_file,'STAMPOFPASSEDRESOURCEEND',$whereitbegins;
1.34      sakharuk  272: 	      print "<br />It has found an error in".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)." <br /> and corrected it.\n";
1.30      sakharuk  273: 	      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";
                    274: 	      $whereitbegins = index $body_log_file,'<inserted text>',$tempobegin+10;
                    275: 	  }
1.29      sakharuk  276: 	  $name_file =~ s/\.tex/\.dvi/;
                    277: 	  my $new_name_file = $name_file;
                    278: 	  $new_name_file =~ s/\.dvi/\.ps/;
1.67      sakharuk  279: 	  my $papera=$paper;
1.62      sakharuk  280: 	  if ($papera eq 'letter') {$papera='';}
                    281: 	  if ($papera ne '') {$papera='-t'.$papera;}
                    282: 	  my $comma = "dvips $papera -Ppdf -G0 -o $new_name_file";
1.59      albertel  283: 	  &busy_wait_command("$comma $name_file 1>/dev/null 2>/dev/null",
                    284: 			     "for $status_statement now Converting to PS",
                    285: 			     \%prog_state,$new_name_file);
1.29      sakharuk  286: 	  if (-e $new_name_file) {
                    287: 	      print "<h1>PDF output file (see link below)</h1>\n";
                    288: 	      $new_name_file =~ m/^(.*)\./;
1.59      albertel  289: 	      my $ps_file = my $tempo_file = $1.'temporar.ps';
                    290: 	      my $pdf_file = $1.'.pdf';
1.29      sakharuk  291: 	      if ($laystyle eq 'album' and $numberofcolumns eq '2') {
                    292: 		  $comma = "psnup -2 -s1.0 $new_name_file";
1.59      albertel  293: 		  &busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null",
                    294: 				     "for $status_statement now Modifying PS layout",
                    295: 				     \%prog_state,$tempo_file); 
1.29      sakharuk  296: 	      } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
1.67      sakharuk  297: 		  my $papera=$paper;
                    298:                   if ($papera eq 'letter') {$papera='';}
1.62      sakharuk  299: 		  if ($papera ne '') {$papera='-p'.$papera;}
                    300: 		  $comma = 'pstops '.$papera.' "2:0+1(0.48w,0)"';
1.63      sakharuk  301: 		  &busy_wait_command("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null",
                    302: 				     "for $status_statement now Modifying PS layout",
                    303: 				     \%prog_state,$tempo_file); 
                    304: 
1.29      sakharuk  305: 	      } else {
1.59      albertel  306: 		  $ps_file=$new_name_file;
1.29      sakharuk  307: 	      }	    
1.59      albertel  308: 	      &busy_wait_command("ps2pdf $ps_file $pdf_file 1>/dev/null 2>/dev/null",
                    309: 				 "for $status_statement now Converting PS to PDF",
                    310: 				 \%prog_state, $pdf_file);
                    311: 
1.29      sakharuk  312: 	      my $texlog = $texfile;
                    313: 	      my $texaux = $texfile;
                    314: 	      my $texdvi = $texfile;
                    315: 	      my $texps = $texfile;
                    316: 	      $texlog =~ s/\.tex/\.log/;
                    317: 	      $texaux =~ s/\.tex/\.aux/;
                    318: 	      $texdvi =~ s/\.tex/\.dvi/;
                    319: 	      $texps =~ s/\.tex/\.ps/;
1.30      sakharuk  320: 	      my @garb = ($texaux,$texdvi,$texps);
1.29      sakharuk  321: #	  unlink @garb;
                    322: 	      unlink $duefile;
1.59      albertel  323: 	      print "<a href=\"/prtspool/$pdf_file\">Your PDF document</a>";
1.75      albertel  324: 	  }
                    325: 	  if ($advanced_role) {  
                    326: 	      print "<br /><br />";
                    327: 	      print "<b><big>The link to ";
                    328: 	      $logfilename=~s/\/home\/httpd//;
                    329: 	      print "<a href=\"$logfilename\">Your log file </a></big></b>";
                    330: 	      print "\n";
                    331: 	      #link tooriginal LaTeX file (included according Michael Hamlin desire)
                    332: 	      my $tex_temporary_file=IO::File->new($texfile) || die "Couldn't open tex file $texfile for reading: $!\n";
                    333: 	      my @tex_content_of_file = <$tex_temporary_file>;
                    334: 	      close $tex_temporary_file; 
                    335: 	      my $body_tex_file = join(' ',@tex_content_of_file);
                    336: 	      $texfile =~ s/\.tex$/aaaaa\.html/;
                    337: 	      $tex_temporary_file = IO::File->new('>'.$texfile); 
                    338: 	      print $tex_temporary_file '<html><head><title>LOGFILE</title></head><body><pre>'.$body_tex_file.'</pre></body></html>'."\n";
                    339: 	      print "<br /><br />";
                    340: 	      print "<b><big>The link to ";
                    341: 	      $texfile=~s/\/home\/httpd//;
                    342: 	      print "<a href=\"$texfile\">Your original LaTeX file </a></big></b>";
                    343: 	      print "\n";
1.29      sakharuk  344: 	  }
                    345:       } else {
                    346: 	  #LaTeX successfully parsed tex file 
                    347: 	  $name_file =~ s/\.tex/\.dvi/;
                    348: 	  my $new_name_file = $name_file;
                    349: 	  $new_name_file =~ s/\.dvi/\.ps/;
1.67      sakharuk  350: 	  my $papera=$paper;
1.62      sakharuk  351: 	  if ($papera eq 'letter') {$papera='';}
                    352: 	  if ($papera ne '') {$papera='-t'.$papera;}
                    353: 	  my $comma = "dvips $papera -Ppdf -G0 -o $new_name_file";
1.59      albertel  354: 	  &busy_wait_command("$comma $name_file 1>/dev/null 2>/dev/null",
                    355: 			     "for $status_statement now Converting to PS",
                    356: 			     \%prog_state,$new_name_file);
1.29      sakharuk  357: 	  if (-e $new_name_file) {
1.61      albertel  358: 	      print "<br />";
1.29      sakharuk  359: 	      $new_name_file =~ m/^(.*)\./;
1.59      albertel  360: 	      my $ps_file = my $tempo_file = $1.'temporar.ps';
                    361: 	      my $pdf_file = $1.'.pdf';
1.29      sakharuk  362: 	      if ($laystyle eq 'album' and $numberofcolumns eq '2') {
                    363: 		  $comma = "psnup -2 -s1.0 $new_name_file";
1.59      albertel  364: 		  &busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null",
                    365: 				     "for $status_statement now Modifying PS layout",
                    366: 				     \%prog_state,$tempo_file);
1.29      sakharuk  367: 	      } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
1.65      sakharuk  368: 		  $papera=~s/t/p/;
                    369: 		  $comma = 'pstops '.$papera.' "2:0+1(0.48w,0)"';
1.59      albertel  370: 		  &busy_wait_command("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null",
                    371: 				     "for $status_statement now Modifying PS layout",
                    372: 				     \%prog_state,$tempo_file); 
1.29      sakharuk  373: 	      } else {
1.59      albertel  374: 		  $ps_file=$new_name_file;
                    375: 	      }
1.67      sakharuk  376: 	      my $addtoPSfile={'legal'=>'<< /PageSize [612 1008] >> setpagedevice',
                    377:                                'tabloid'=>'<< /PageSize [792 1224] >> setpagedevice',
                    378:                                'executive'=>,'<< /PageSize [540 720] >> setpagedevice',
                    379:                                'a2'=>'<< /PageSize [1195.02 1690.09] >> setpagedevice',
                    380:                                'a3'=>'<< /PageSize [842 1195.02] >> setpagedevice',
                    381:                                'a4'=>'<< /PageSize [595.2 842] >> setpagedevice',
                    382:                                'a5'=>'<< /PageSize [421.1 595.2] >> setpagedevice',
                    383:                                'a6'=>'<< /PageSize [298.75 421.1] >> setpagedevice',
                    384: 			   };
                    385: 	      if ($paper ne 'letter') {
1.69      matthew   386: 		  open(FFH,'<',$ps_file) || die "Couldn't open ps file $ps_file for reading: $!\n";
1.63      sakharuk  387: 		  my $new_ps_file='new'.$ps_file;
1.69      matthew   388: 		  open(FFHS,'>',$new_ps_file) || die "Couldn't open new ps file $new_ps_file for reading: $!\n";
1.67      sakharuk  389: 		  print FFHS $addtoPSfile->{$paper}."\n";
1.63      sakharuk  390: 		  while (<FFH>) {
                    391: 		      print FFHS $_;
                    392: 		  }
1.62      sakharuk  393: 		  close(FFH);
1.63      sakharuk  394: 		  close(FFHS);
                    395: 		  $ps_file=$new_ps_file;	  
1.62      sakharuk  396: 	      }
1.59      albertel  397: 	      &busy_wait_command("ps2pdf $ps_file $pdf_file 1>/dev/null 2>/dev/null",
                    398: 				 "for $status_statement now Converting PS to PDF",
                    399: 				 \%prog_state,$pdf_file);
                    400: 	    
1.29      sakharuk  401: 	      my $texlog = $texfile;
                    402: 	      my $texaux = $texfile;
                    403: 	      my $texdvi = $texfile;
                    404: 	      my $texps = $texfile;
                    405: 	      $texlog =~ s/\.tex/\.log/;
                    406: 	      $texaux =~ s/\.tex/\.aux/;
                    407: 	      $texdvi =~ s/\.tex/\.dvi/;
                    408: 	      $texps =~ s/\.tex/\.ps/;
                    409: 	      my @garb = ($texlog,$texaux,$texdvi,$texps);
1.22      sakharuk  410: #	  unlink @garb;
1.29      sakharuk  411: 	      unlink $duefile;
1.68      sakharuk  412: 	      print "<a href=\"/prtspool/$pdf_file\">$link_text - click here to download pdf</a>";
1.29      sakharuk  413: 	      print "\n";
                    414: 	  }
1.63      sakharuk  415:       }  
1.29      sakharuk  416:   } else {
                    417:       print "LaTeX file $texfile was not created successfully";
1.14      sakharuk  418:   }
1.43      sakharuk  419: }
1.45      sakharuk  420: print "<br />";
1.44      sakharuk  421: if ($number_of_files>1) {
1.45      sakharuk  422:     my $zipfile=$texfile[0];
                    423:     $zipfile=~s/\.tex/\.zip/;
                    424:     my $statement="zip $zipfile";
1.44      sakharuk  425:     foreach my $file (@texfile) {
1.45      sakharuk  426: 	$file=~s/\.tex/.\pdf/;
                    427: 	$statement.=' '.$file; 
1.44      sakharuk  428:     }
1.49      albertel  429:     print("<pre>Zip Output:\n");
                    430:     system($statement);
                    431:     print("</pre>");
1.45      sakharuk  432:     $zipfile=~s/\/home\/httpd//;
1.49      albertel  433:     print "<br /> A <a href=\"$zipfile\">ZIP file</a> of all the PDFs.";
1.44      sakharuk  434: }
1.49      albertel  435: if ($adv) { &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state); }
1.1       sakharuk  436: 
1.59      albertel  437: my $done;
                    438: sub REAPER {
                    439:     $done=1;
                    440: }
                    441: 
                    442: sub busy_wait_command {
                    443:     my ($command,$message,$progress_win,$output_file)=@_;
                    444:     
                    445:     $SIG{CHLD} = \&REAPER;
                    446:     $done=0;
                    447:     my $pid=open(CMD,"$command |");
1.60      albertel  448:     if ($adv) {
                    449: 	&Apache::lonhtmlcommon::Update_PrgWin('',$progress_win,$message);
                    450:     }
1.59      albertel  451:     while(!$done) {
                    452: 	sleep 1;
                    453: 	my $extra_msg;
                    454: 	if ($output_file) {
                    455: 	    my $size=(stat($output_file))[7];
                    456: 	    $extra_msg=", $size bytes generated";
                    457: 	}
1.60      albertel  458: 	if ($adv) {
                    459: 	    &Apache::lonhtmlcommon::Update_PrgWin('',$progress_win,
                    460: 						  $message.$extra_msg);
                    461: 	}
1.59      albertel  462:     }
                    463:     $SIG{CHLD}='IGNORE';
                    464:     close(CMD);
                    465: }
1.1       sakharuk  466: 
                    467: 
                    468: 
1.4       sakharuk  469: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>