[LON-CAPA-cvs] cvs: loncom /interface lonhelper.pm lonnavmaps.pm lonprintout.pm printout.pl

raeburn raeburn at source.lon-capa.org
Thu Mar 12 09:25:47 EDT 2026


raeburn		Thu Mar 12 13:25:47 2026 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm lonhelper.pm printout.pl 
                     	lonnavmaps.pm 
  Log:
  - Bug 6121
    When Form Fields in use and PDF(s) and problem(s) selected as resources
    to print, number of columns automatically set to 1 and PDF creation via
    gs -sDEVICE=pdfwrite -dUNROLLFORMS -dCompatibilityLevel=1.5
    instead of via ps2pdf, so Form Fields will be preserved.
  
  
-------------- next part --------------
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.715 loncom/interface/lonprintout.pm:1.716
--- loncom/interface/lonprintout.pm:1.715	Thu Mar 12 12:56:02 2026
+++ loncom/interface/lonprintout.pm	Thu Mar 12 13:25:47 2026
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.715 2026/03/12 12:56:02 raeburn Exp $
+# $Id: lonprintout.pm,v 1.716 2026/03/12 13:25:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -334,10 +334,12 @@
 	$filter,
 	$choice_func,
 	$value_func,
-	$start_new_option)  = @_;
+	$start_new_option,
+	$pdfs_and_formfields_warning) = @_;
 
     my $result = <<CHOOSE_RESOURCES;
 <state name="$this_state" title="$prompt_text">
+    $pdfs_and_formfields_warning
     <resource variable="$variable" $resource_options
               closeallpages="1">
       <nextstate>$next_state</nextstate>
@@ -449,6 +451,9 @@
 sub generate_common_choosers {
     my ($r,$helper,$map,$url,$isProblem,$symbFilter,$start_new_option) = @_;
 
+    my $pdfs_and_formfields_warning =
+        &get_pdfs_with_formfields_warning($helper, $map);
+
     # code for a few states used for printout launched from both
     # /adm/navmaps and from a resource by a privileged user:
     #   - To allow resources to be selected for printing.
@@ -568,7 +573,7 @@
                                                $isProblem, '',  $symbFilter,
                                                $start_new_option);
     &Apache::lonxml::xmlparse($r, 'helper', $anon_page);
-    return ($codechoice,$code_selection,$namechoice);
+    return ($pdfs_and_formfields_warning,$codechoice,$code_selection,$namechoice);
 }
 
 #  Returns the XML for choosing how assignments are to be formatted
@@ -994,6 +999,7 @@
 #
 # Parameters:
 #   pdf_uri   - URI of the PDF file to include.
+#   $pdfFormFields - yes if 'with PDF Form Fields' selected in layout options
 #
 # Returns:
 #  The LaTeX to include.
@@ -1004,7 +1010,7 @@
 #
 #
 sub include_pdf {
-    my ($pdf_uri) = @_;
+    my ($pdf_uri,$pdfFormFields) = @_;
 
     # Where is the file? If not local we'll need to repcopy it:'
 
@@ -1035,7 +1041,7 @@
     $base =~ s/ /\_/g;
 
 
-    my $output = &print_latex_header();
+    my $output = &print_latex_header('',$pdfFormFields);
     $output    .= '\special{ps: _begin_job_ ('
 	.$base.'.pdf.eps'.
 	')run _end_job_}';
@@ -2433,7 +2439,6 @@
     return $result;
 }
 
-
 #
 # List of recently generated print files
 #
@@ -2741,7 +2746,7 @@
 		$texversion .= '\cleardoublepage';
 	    }
 
-	    $texversion .= &include_pdf($urlp);
+	    $texversion .= &include_pdf($urlp,$pdfFormFields);
 	    $texversion = &latex_header_footer_remove($texversion);
 	    if ($member != $#order) {
 		$texversion .= '\\ \cleardoublepage';
@@ -3037,7 +3042,7 @@
 	    $do_postprocessing = 0; # Don't massage the result.
 
 	} elsif ($cleanURL =~ /\.pdf$/i) {
-	    $result .= &include_pdf($cleanURL);
+	    $result .= &include_pdf($cleanURL,$pdfFormFields);
 	    $result .= '\end{document}';
 	} elsif ($cleanURL =~ /\.page$/i) { #  Print page in non construction space contexts.
 
@@ -3233,7 +3238,7 @@
 		if ($i > 0) {
 		    $result .= '\cleardoublepage';
 		}
-                my $texfrompdf = &include_pdf($urlp);
+                my $texfrompdf = &include_pdf($urlp,$pdfFormFields);
                 if ($flag_latex_header_remove ne 'NO') {
                     $texfrompdf = &latex_header_footer_remove($texfrompdf);
                 }
@@ -3760,7 +3765,6 @@
     if (&can_use_pdfforms($helper) && $pdfFormFields) {
         &Apache::lonnet::appenv({'cgi.'.$identifier.'.pdfFormFields' => $pdfFormFields});
     }
-
     my $end_page = &Apache::loncommon::end_page();
     my $continue_text = &mt('Continue');
     # If there's been an unrecoverable SSI error, report it to the user
@@ -3966,7 +3970,7 @@
 		    $current_output .= $rendered.'\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\strut \vskip 0 mm \strut ';
 		} elsif($res_url =~ /\.pdf$/) {
 		    my $url = &Apache::lonnet::clutter($res_url);
-		    my $rendered  = &include_pdf($url);
+		    my $rendered  = &include_pdf($url,$pdfFormFields);
 		    if ($remove_latex_header ne 'NO') {
 			$rendered = &latex_header_footer_remove($rendered);
 		    }
@@ -4152,6 +4156,52 @@
     }
 }
 
+sub get_pdfs_with_formfields_warning {
+    my ($helper,$map) = @_;
+
+    my ($message,$numberofcolumns,$pdfFormFields);
+
+    if ((exists($env{'form.FORMAT.cols'})) && (exists($env{'form.FORMAT.pdfFormFields'}))) {
+       $numberofcolumns = $env{'form.FORMAT.cols'};
+       $pdfFormFields = $env{'form.FORMAT.pdfFormFields'};
+    } else {
+        my @temporary_array=split(/\|/,$helper->{'VARS'}->{'FORMAT'});
+        $numberofcolumns = $temporary_array[1];
+        $pdfFormFields = $temporary_array[3];
+    }
+    if (($pdfFormFields eq 'yes') && ($numberofcolumns == 2)) {
+        my $navmap = Apache::lonnavmaps::navmap->new();
+        if (defined($navmap)) {
+            my $res = $navmap->getResourceByUrl($map);
+            if ($res) {
+                my $func = sub { return ($_[0]->is_pdf()); };
+                my @pdfs = $navmap->retrieveResources($res, $func,1,1,1);
+                if (@pdfs) {
+                    $func = sub { return ($_[0]->is_raw_problem()); };
+                    my @problems = $navmap->retrieveResources($res, $func,1,1,1);
+                    if (@problems) {
+                        $message = 
+                            '<p>'.
+                            &mt('Available resource types include both PDFs and problems.').
+                            '</p><p>'.
+                            &mt("If the set of resources you select contains both, the number of columns will automatically be set to [_1]one[_2], because 'with Form Fields' was specified.",
+                                '<b>','</b>').
+                            '<br />'.
+                            &mt("To use a [_1]two[_2] column format, either use 'Back' to change layout to 'without Form Fields', or avoid selecting both resource types on this page.",
+                                '<b>','</b>').
+                            '</p>';
+                        return '<message type="warning">'.$message.'</message>';
+                    }
+                }
+            }
+        } else {
+            $message = "Retrieval of information about resource types failed.";
+            return '<message type="warning">'.$message.'</message>';
+        }
+    }
+    return;
+}
+
 sub printHelper {
     my $r = shift;
 
@@ -4554,6 +4604,8 @@
 	    push(@{$printChoices}, [$optionText,
 				    'map_problems_pages',
 				    'CHOOSE_PROBLEMS_HTML']);
+            my $pdfs_and_formfields_warning =
+                &get_pdfs_with_formfields_warning($helper, $map);
 	    my $helperFragment = &generate_resource_chooser('CHOOSE_PROBLEMS',
 							    'Select Problem(s) to print',
 							    'multichoice="1" toponly="1" addstatus="1" closeallpages="1" modallink="1" nocurrloc="'.$nocurrloc.'"',
@@ -4571,7 +4623,8 @@
 							  $map,
 							  $isNotMap, '',
 							  $symbFilter,
-							  $start_new_option);
+							  $start_new_option,
+                                                          $pdfs_and_formfields_warning);
 
 	    &Apache::lonxml::xmlparse($r, 'helper', $helperFragment);
 	} else {
@@ -4661,7 +4714,7 @@
 				    'problems_for_anon', 'CHOOSE_ANON1']);
 	}
 
-        my ($codechoice,$code_selection,$namechoice) =
+        my ($pdfs_and_formfields_warning,$codechoice,$code_selection,$namechoice) =
             &generate_common_choosers($r,$helper,$map,$url,$isProblem,$symbFilter,$start_new_option);
 
 	if ($helper->{VARS}->{'assignment'}) {
@@ -4684,6 +4737,7 @@
 
 	my $resource_selector=<<RESOURCE_SELECTOR;
     <state name="SELECT_RESOURCES" title="Select Resources">
+    $pdfs_and_formfields_warning
     <nextstate>PRINT_FORMATTING</nextstate>
     <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
     <resource variable="RESOURCES" multichoice="1" addstatus="1"
@@ -4849,7 +4903,7 @@
                          '<b>','</b>','<b>','</b>','<b>','</b>'),
                          'select_sequences_resources_for_anon','CHOOSE_SEQUENCE_ANON2']);
                 if ($escapedSequenceName) {
-                    my ($codechoice,$code_selection,$namechoice) =
+                    my ($pdfs_and_formfields_warning,$codechoice,$code_selection,$namechoice) =
                         &generate_common_choosers($r,$helper,$escapedSequenceName,$escapedSequenceName,
                                                   $isProblem,$symbFilter,$start_new_option);
 
@@ -4864,6 +4918,7 @@
 
     </state>
     <state name="SELECT_RESOURCES" title="Select Resources">
+    $pdfs_and_formfields_warning
     <nextstate>PRINT_FORMATTING</nextstate>
     <message>(mark desired resources then click "next" button) <br /></message>
     <resource variable="RESOURCES" multichoice="1" addstatus="1"
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.205 loncom/interface/lonhelper.pm:1.206
--- loncom/interface/lonhelper.pm:1.205	Sat Dec 13 05:56:01 2025
+++ loncom/interface/lonhelper.pm	Thu Mar 12 13:25:47 2026
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.205 2025/12/13 05:56:01 raeburn Exp $
+# $Id: lonhelper.pm,v 1.206 2026/03/12 13:25:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2595,6 +2595,26 @@
 	}
     }
 
+    if (($helper->{TITLE} eq 'Printing Helper') &&
+        (exists($helper->{'VARS'}->{'FORMAT'}))) {
+        my @format = split(/\|/,$helper->{'VARS'}->{'FORMAT'});
+        my ($numberofcolumns,$pdfFormFields) = ($format[1],$format[3]);
+        if (($numberofcolumns == 2) && ($pdfFormFields eq 'yes')) {
+            my ($has_pdf,$has_prob) = (0,0);
+            foreach my $item (split(/\|\|\|/,$helper->{VARS}->{$self->{'variable'}})) {
+                last if ($has_pdf && $has_prob);
+                if ($item =~ /\.pdf$/) {
+                    $has_pdf = 1;
+                } elsif ($item =~ /$LONCAPA::assess_re/) {
+                    $has_prob = 1;
+                }
+            }
+            if ($has_pdf && $has_prob) {
+                $format[1] = 1;
+                $helper->{'VARS'}->{'FORMAT'} = join('|', at format);
+            }
+        }
+    }
 
     if (defined($self->{NEXTSTATE})) {
         $helper->changeState($self->{NEXTSTATE});
Index: loncom/interface/printout.pl
diff -u loncom/interface/printout.pl:1.180 loncom/interface/printout.pl:1.181
--- loncom/interface/printout.pl:1.180	Thu Mar 12 12:00:35 2026
+++ loncom/interface/printout.pl	Thu Mar 12 13:25:47 2026
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 # CGI-script to run LaTeX, dvips, ps2ps, ps2pdf etc.
 #
-# $Id: printout.pl,v 1.180 2026/03/12 12:00:35 raeburn Exp $
+# $Id: printout.pl,v 1.181 2026/03/12 13:25:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -236,7 +236,6 @@
 my $student_names = $env{'cgi.'.$identifier.'.studentnames'};
 my $backref = &unescape($env{'cgi.'.$identifier.'.backref'});
 
-
 my @names_pack=();
 if ($student_names=~/_END_/) {  
     @names_pack=split(/_ENDPERSON_/,$student_names);
@@ -561,6 +560,11 @@
 	      # Use gs to fix the postscript -> level 1.5 
 	      # .. if pdfs were included
 	      #
+	      # if use of form fields was specified set device to pdfwrite and
+	      # include -dUNROLLFORMS in gs command and generate PDFs immediately.
+	      #
+	      # if not, check whether ps2write is available.
+	      #
 	      # pswrite device was removed from ghostscript 9.09 and later,
 	      # (ps2write device is used instead).
 	      # check which device is available, and use as the value
@@ -568,139 +572,155 @@
 	      #
 
 	      if ($pdfs_converted > 0) {
-		  my @possdevices = qw(ps2write pswrite);
-		  my $device;
-		  foreach my $poss (@possdevices) {
-		      if (open(PIPE,"gs -h |grep ' $poss ' 2>&1 |")) {
-		          my $output = <PIPE>;
-		          close(PIPE);
-		          chomp($output);
-		          if ($output =~ /\Q $poss \E/) {
-		              $device = $poss;
+                  my ($major,$minor);
+                  if (open(PIPE,"gs -v |grep 'GPL Ghostscript' 2>&1 |")) {
+                      my $info = <PIPE>;
+                      close(PIPE);
+                      chomp($info);
+                      if ($info =~ /Ghostscript\s+(\d+)\.(\d+)/) {
+                          ($major,$minor) = ($1,$2);
+                      }
+                  }
+                  if ($pdfFormFields eq 'yes') {
+                      $comma = "gs -sDEVICE=pdfwrite -dUNROLLFORMS ";
+                      if (($major > 9) || (($major == 9) && ($minor >= 50))) {
+                          $comma .= '--permit-file-read=* ';
+                      }
+                      &busy_wait_command("$comma -o $pdf_file $new_name_file 2>/dev/null 1>/dev/null",
+                                         "for $status_statement now Converting PS to PDF",
+                                         \%prog_state, $pdf_file);
+                      # unlink ps file after use as it can be large
+                      if ($new_name_file =~ m{^\Q$printfor\E_printout_\Q$file_id\E(|temporar)\.ps$}) {
+                          if (-e $new_name_file) {
+                              unlink($new_name_file);
+                          }
+                      }
+                  } else {
+		      my @possdevices = qw(ps2write pswrite);
+		      my $device;
+		      foreach my $poss (@possdevices) {
+		          if (open(PIPE,"gs -h |grep ' $poss ' 2>&1 |")) {
+		              my $output = <PIPE>;
+		              close(PIPE);
+		              chomp($output);
+		              if ($output =~ /\Q $poss \E/) {
+		                  $device = $poss;
+		              }
 		          }
+		          last if ($device ne '');
 		      }
-		      last if ($device ne '');
-		  }
-		  if ($device ne '') {
-		      my ($major,$minor);
-		      if (open(PIPE,"gs -v |grep 'GPL Ghostscript' 2>&1 |")) {
-		          my $info = <PIPE>;
-		          close(PIPE);
-		          chomp($info);
-		          if ($info =~ /Ghostscript\s+(\d+)\.(\d+)/) {
-		              ($major,$minor) = ($1,$2);
+		      if ($device ne '') {
+		          $comma = "gs -sDEVICE=$device ";
+		          if ($device eq 'pswrite') {
+		              $comma .= '-dLanguageLevel=1.5 ';
+		          }
+		          if (($major > 9) || (($major == 9) && ($minor >= 50))) {
+		              $comma .= '--permit-file-read=* ';
+		          }
+		          &busy_wait_command("$comma -o $tempo_file $new_name_file 2>/dev/null 1>/dev/null",
+				             "for $status_statement now validating PS",
+				             \%prog_state, $tempo_file);
+		          if (-e $tempo_file) {
+		              &busy_wait_command("mv $tempo_file $new_name_file",
+				                 'File move', \%prog_state, $new_name_file);
 		          }
-		      }
-		      $comma = "gs -sDEVICE=$device ";
-		      if ($device eq 'pswrite') {
-		          $comma .= '-dLanguageLevel=1.5 ';
-		      }
-		      if (($major > 9) || (($major == 9) && ($minor >= 50))) {
-		          $comma .= '--permit-file-read=* ';
-		      }
-		      &busy_wait_command("$comma -o $tempo_file $new_name_file 2>/dev/null 1>/dev/null",
-				         "for $status_statement now validating PS",
-				         \%prog_state, $tempo_file);
-
-#---
-		      if (-e $tempo_file) {
-		          &busy_wait_command("mv $tempo_file $new_name_file",
-				             'File move', \%prog_state, $new_name_file);
 		      }
 		  }
 	      }
-	      if ($laystyle eq 'album' and $numberofcolumns eq '2') {
-		  my $canscale;
-		  if (open(PIPE,"psnup --version 2>&1 |")) {
-		      while (<PIPE>) {
-			  chomp();
-                          next if (/pstops:\s+invalid\s+option/);
-                          if (/^psnup\s+release\s+(\d+)\s+patchlevel\s+(\d+)/) {
-                              if (($1 == 1) && ($2 < 90)) {
-                                  $canscale = 1;
-                              }
-                              last;
-                          } elsif (/^psnup\s+(\d+)\.(\d+)/) {
-                              if (($1 == 1) && ($2 < 90)) {
-                                  $canscale = 1;
+              unless ($pdfs_converted && $pdfFormFields) {
+	          if ($laystyle eq 'album' and $numberofcolumns eq '2') {
+		      my $canscale;
+		      if (open(PIPE,"psnup --version 2>&1 |")) {
+		          while (<PIPE>) {
+			      chomp();
+                              next if (/pstops:\s+invalid\s+option/);
+                              if (/^psnup\s+release\s+(\d+)\s+patchlevel\s+(\d+)/) {
+                                  if (($1 == 1) && ($2 < 90)) {
+                                      $canscale = 1;
+                                  }
+                                  last;
+                              } elsif (/^psnup\s+(\d+)\.(\d+)/) {
+                                  if (($1 == 1) && ($2 < 90)) {
+                                      $canscale = 1;
+                                  }
+                                  last;
                               }
-                              last;
-                          }
+		          }
+		          close(PIPE);
 		      }
-		      close(PIPE);
-		  }
-		  if ($canscale) {
-		      $comma = "psnup $papera -2 -s1.0 $new_name_file";
-                      &debug("PSNUP command: $comma");
-                  } elsif (($paper eq 'letter') || ($paper eq 'legal') || ($paper eq 'a4')) {
-                      my ($ptype,$xoff,$yoffl,$yoffr,$units) = &get_pstops_offsets($paper);
-                      $comma = "pstops $ptype '2:0L\@1.0($xoff$units,$yoffl$units)+1L\@1.0($xoff$units,$yoffr$units)' $new_name_file";
-                      &debug("PSTOPS command: $comma");
-		  } else {
-		      $comma = "psnup $papera -2 $new_name_file";
-                      &debug("PSNUP command: $comma");
-		  }
-		  &busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null",
-				     "for $status_statement now Modifying PS layout",
-				     \%prog_state,$tempo_file);
-                  # unlink ps file after use as it can be large
-                  if ($name_file_ps eq $printfor.'_printout_'.$file_id.'.ps') {
-                      if (-e $name_file_ps) {
-                          unlink($name_file_ps);
+		      if ($canscale) {
+		          $comma = "psnup $papera -2 -s1.0 $new_name_file";
+                          &debug("PSNUP command: $comma");
+                      } elsif (($paper eq 'letter') || ($paper eq 'legal') || ($paper eq 'a4')) {
+                          my ($ptype,$xoff,$yoffl,$yoffr,$units) = &get_pstops_offsets($paper);
+                          $comma = "pstops $ptype '2:0L\@1.0($xoff$units,$yoffl$units)+1L\@1.0($xoff$units,$yoffr$units)' $new_name_file";
+                          &debug("PSTOPS command: $comma");
+		      } else {
+		          $comma = "psnup $papera -2 $new_name_file";
+                          &debug("PSNUP command: $comma");
+		      }
+		      &busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null",
+				         "for $status_statement now Modifying PS layout",
+				         \%prog_state,$tempo_file);
+                      # unlink ps file after use as it can be large
+                      if ($name_file_ps eq $printfor.'_printout_'.$file_id.'.ps') {
+                          if (-e $name_file_ps) {
+                              unlink($name_file_ps);
+                          }
                       }
-                  }
-	      } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
-		  $comma = 'pstops '.$papera.' "2:0+1(0.48w,0)" '.$new_name_file;
-		  &debug("PSTOPS command: $comma ");
-		  &busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null",
-				     "for $status_statement now Modifying PS layout",
-				     \%prog_state,$tempo_file);
+	          } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
+		      $comma = 'pstops '.$papera.' "2:0+1(0.48w,0)" '.$new_name_file;
+		      &debug("PSTOPS command: $comma ");
+		      &busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null",
+			    	         "for $status_statement now Modifying PS layout",
+				         \%prog_state,$tempo_file);
+                      # unlink ps file after use as it can be large
+                      if ($name_file_ps eq $printfor.'_printout_'.$file_id.'.ps') {
+                          if (-e $name_file_ps) {
+                              unlink($name_file_ps);
+                          }
+                      }
+	          } else {
+		      $ps_file=$new_name_file;
+	          }
+                  my $addtoPSfile={'letter'=>'<< /PageSize [612 792] >> setpagedevice',
+                                   'legal'=>'<< /PageSize [612 1008] >> setpagedevice',
+                                   'tabloid'=>'<< /PageSize [792 1224] >> setpagedevice',
+                                   'executive'=>,'<< /PageSize [540 720] >> setpagedevice',
+                                   'a2'=>'<< /PageSize [1195.02 1690.09] >> setpagedevice',
+                                   'a3'=>'<< /PageSize [842 1195.02] >> setpagedevice',
+                                   'a4'=>'<< /PageSize [595.2 842] >> setpagedevice',
+                                   'a5'=>'<< /PageSize [421.1 595.2] >> setpagedevice',
+                                   'a6'=>'<< /PageSize [298.75 421.1] >> setpagedevice',
+                                  };
+	          open(FFH,'<',$ps_file) || die "Couldn't open ps file $ps_file for reading: $!\n";
+	          my $new_ps_file='new'.$ps_file;
+	          open(FFHS,'>',$new_ps_file) || die "Couldn't open new ps file $new_ps_file for reading: $!\n";
+	          print FFHS $addtoPSfile->{$paper}."\n";
+	          while (<FFH>) {
+	              print FFHS $_;
+	          }
+	          close(FFH);
+	          close(FFHS);
                   # unlink ps file after use as it can be large
-                  if ($name_file_ps eq $printfor.'_printout_'.$file_id.'.ps') {
-                      if (-e $name_file_ps) {
-                          unlink($name_file_ps);
+                  if ($ps_file =~ m{^\Q$printfor\E_printout_\Q$file_id\E(|temporar)\.ps$}) {
+                      if (-e $ps_file) {
+                          unlink($ps_file);
                       }
                   }
-	      } else {
-		  $ps_file=$new_name_file;
-	      }
-              my $addtoPSfile={'letter'=>'<< /PageSize [612 792] >> setpagedevice',
-                               'legal'=>'<< /PageSize [612 1008] >> setpagedevice',
-                               'tabloid'=>'<< /PageSize [792 1224] >> setpagedevice',
-                               'executive'=>,'<< /PageSize [540 720] >> setpagedevice',
-                               'a2'=>'<< /PageSize [1195.02 1690.09] >> setpagedevice',
-                               'a3'=>'<< /PageSize [842 1195.02] >> setpagedevice',
-                               'a4'=>'<< /PageSize [595.2 842] >> setpagedevice',
-                               'a5'=>'<< /PageSize [421.1 595.2] >> setpagedevice',
-                               'a6'=>'<< /PageSize [298.75 421.1] >> setpagedevice',
-                              };
-	      open(FFH,'<',$ps_file) || die "Couldn't open ps file $ps_file for reading: $!\n";
-	      my $new_ps_file='new'.$ps_file;
-	      open(FFHS,'>',$new_ps_file) || die "Couldn't open new ps file $new_ps_file for reading: $!\n";
-	      print FFHS $addtoPSfile->{$paper}."\n";
-	      while (<FFH>) {
-	          print FFHS $_;
-	      }
-	      close(FFH);
-	      close(FFHS);
-              # unlink ps file after use as it can be large
-              if ($ps_file =~ m{^\Q$printfor\E_printout_\Q$file_id\E(|temporar)\.ps$}) {
-                  if (-e $ps_file) {
+                  $ps_file=$new_ps_file;
+                  $comma = 'ps2pdf13';
+                  if ($pdfFormFields eq 'yes') {
+                      $comma = 'ps2pdf -dCompatibilityLevel=1.5';
+                  }
+		  &busy_wait_command("$comma $ps_file $pdf_file 1>/dev/null 2>/dev/null",
+				     "for $status_statement now Converting PS to PDF",
+				     \%prog_state,$pdf_file);
+                  # unlink ps file after use as it can be large
+                  if ($ps_file =~ m{^new\Q$printfor\E_printout_\Q$file_id\E(|temporar)\.ps$}) {
                       unlink($ps_file);
                   }
-              }
-              $ps_file=$new_ps_file;
-              $comma = 'ps2pdf13';
-              if ($pdfFormFields eq 'yes') {
-                  $comma = 'ps2pdf -dCompatibilityLevel=1.5';
-              }
-              &busy_wait_command("$comma $ps_file $pdf_file 1>/dev/null 2>/dev/null",
-				 "for $status_statement now Converting PS to PDF",
-				 \%prog_state,$pdf_file);
-              # unlink ps file after use as it can be large
-              if ($ps_file =~ m{^new\Q$printfor\E_printout_\Q$file_id\E(|temporar)\.ps$}) {
-                  unlink($ps_file);
-              }
+	      }
 
 	      my $texlog = $texfile;
 	      my $texaux = $texfile;
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.585 loncom/interface/lonnavmaps.pm:1.586
--- loncom/interface/lonnavmaps.pm:1.585	Fri Dec 19 21:30:55 2025
+++ loncom/interface/lonnavmaps.pm	Thu Mar 12 13:25:47 2026
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.585 2025/12/19 21:30:55 raeburn Exp $
+# $Id: lonnavmaps.pm,v 1.586 2026/03/12 13:25:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4813,6 +4813,11 @@
     my $src = $self->src();
     return ($src =~ /html$/);
 }
+sub is_pdf {
+    my $self=shift;
+    my $src = $self->src();
+    return ($src =~ /\.pdf$/i);
+}
 sub is_map { my $self=shift; return defined($self->navHash("is_map_", 1)); }
 sub is_page {
     my $self=shift;


More information about the LON-CAPA-cvs mailing list