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

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

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