[LON-CAPA-cvs] cvs: loncom /interface printout.pl

foxr lon-capa-cvs@mail.lon-capa.org
Tue, 06 Jun 2006 11:04:19 -0000


foxr		Tue Jun  6 07:04:19 2006 EDT

  Modified files:              
    /loncom/interface	printout.pl 
  Log:
  strip the STARTOFSTUDENT/ENDOFSTUDENT stamps from the initial postscript
  This is an intermediate development stage of request 4786... later
  this will be extended to count the pages between each of these stamps
  and subsequently ensure that the output for all student assignments in 
  a single printout will be the same number of page/columns.
  
  
Index: loncom/interface/printout.pl
diff -u loncom/interface/printout.pl:1.98 loncom/interface/printout.pl:1.99
--- loncom/interface/printout.pl:1.98	Mon Apr 24 17:30:06 2006
+++ loncom/interface/printout.pl	Tue Jun  6 07:04:18 2006
@@ -475,6 +475,7 @@
 			     "for $status_statement now Converting to PS",
 			     \%prog_state,$new_name_file);
 	  if (-e $new_name_file) {
+	      &repaginate_postscript($new_name_file);
 	      print "<h1>PDF output file (see link below)</h1>\n";
 	      $new_name_file =~ m/^(.*)\./;
 	      my $ps_file = my $tempo_file = $1.'temporar.ps';
@@ -549,6 +550,7 @@
 			     "for $status_statement now Converting to PS",
 			     \%prog_state,$new_name_file);
 	  if (-e $new_name_file) {
+	      &repaginate_postscript($new_name_file);
 	      print "<br />";
 	      $new_name_file =~ m/^(.*)\./;
 	      my $ps_file = my $tempo_file = $1.'temporar.ps';
@@ -659,5 +661,27 @@
 }
 
 
+#  Repagninate a postscript file.
+#  What we need to do:
+#   - Count the number of pages in each student.
+#   - Add pages between each student so that each student's output is
+#     the maximum number of pages.
+#   
+sub repaginate_postscript {
+    # For now just strip out the STARTOFSTUDENTSTAMP
+    # ENDOFSTUDENTSTAMP markers in the postscript.
+
+    my ($postscript_filename) = @_;
+    open(PSFILE, "<$postscript_filename");
+    my @psfilelines = <PSFILE>;
+    close(PSFILE);
+    my $psbody = join('', @psfilelines);
+    $psbody =~ s/STARTOFSTUDENTSTAMP//g;
+    $psbody =~ s/ENDOFSTUDENTSTAMP//g;
 
+    open(PSFILE, ">$postscript_filename");
+    print PSFILE $psbody;
+
+    close PSFILE;
+}