Funktion zum direkten Ausdrucken von PDF-Dokumenten aus dem ReportGenerator heraus...
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 22 Jan 2008 16:49:54 +0000 (16:49 +0000)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 22 Jan 2008 16:49:54 +0000 (16:49 +0000)
SL/ReportGenerator.pm

index 2a40ab5..b028302 100644 (file)
@@ -601,12 +601,29 @@ sub render_pdf_with_pdf_api2 {
     }
   }
 
-  my $filename = $self->get_attachment_basename();
+  my $content = $pdf->stringify();
 
-  print qq|content-type: application/pdf\n|;
-  print qq|content-disposition: attachment; filename=${filename}.pdf\n\n|;
+  my $printer_command;
+  if ($params->{print} && $params->{printer_id}) {
+    $form->{printer_id} = $params->{printer_id};
+    $form->get_printer_code($myconfig);
+    $printer_command = $form->{printer_command};
+  }
+
+  if ($printer_command) {
+    $self->_print_content('printer_command' => $printer_command,
+                          'content'         => $content,
+                          'copies'          => $params->{copies});
+    $form->{report_generator_printed} = 1;
+
+  } else {
+    my $filename = $self->get_attachment_basename();
+
+    print qq|content-type: application/pdf\n|;
+    print qq|content-disposition: attachment; filename=${filename}.pdf\n\n|;
 
-  print $pdf->stringify();
+    print $content;
+  }
 }
 
 sub verify_paper_size {
@@ -712,15 +729,9 @@ END
     unlink $cfg_file_name, $html_file_name;
 
     if ($printer_command && $content) {
-      foreach my $i (1 .. max $opt->{copies}, 1) {
-        my $printer = IO::File->new("| ${printer_command}");
-        if (!$printer) {
-          $form->error($locale->text('Could not spawn the printer command.'));
-        }
-        $printer->print($content);
-        $printer->close();
-      }
-
+      $self->_print_content('printer_command' => $printer_command,
+                            'content'         => $content,
+                            'copies'          => $opt->{copies});
       $form->{report_generator_printed} = 1;
     }
 
@@ -730,6 +741,18 @@ END
   }
 }
 
+sub _print_content {
+  my $self   = shift;
+  my %params = @_;
+
+  foreach my $i (1 .. max $params{copies}, 1) {
+    my $printer = IO::File->new("| $params{printer_command}");
+    $main::form->error($main::locale->text('Could not spawn the printer command.')) if (!$printer);
+    $printer->print($params{content});
+    $printer->close();
+  }
+}
+
 sub generate_pdf_content {
   my $self = shift;