Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d33ad436

Von Moritz Bunkus vor mehr als 16 Jahren hinzugefügt

  • ID d33ad436ea3f511f21bfdaa3987b9102db1f0731
  • Vorgänger 07948c34
  • Nachfolger 1de28336

Unterstützung für die Ausgabe der ReportGenerator-Ergebnisse als PDF via html2ps entfernt.

Unterschiede anzeigen:

SL/ReportGenerator.pm
9 9

  
10 10
# Cause locales.pl to parse these files:
11 11
# parse_html_template('report_generator/html_report')
12
# parse_html_template('report_generator/pdf_report')
13 12

  
14 13
sub new {
15 14
  my $type = shift;
......
26 25
    'allow_pdf_export'      => 1,
27 26
    'allow_csv_export'      => 1,
28 27
    'html_template'         => 'report_generator/html_report',
29
    'pdf_template'          => 'report_generator/pdf_report',
30 28
    'pdf_export'            => {
31 29
      'paper_size'          => 'a4',
32 30
      'orientation'         => 'landscape',
......
342 340

  
343 341
  my @export_variables = $self->{form}->flatten_variables(@{ $self->{export}->{variable_list} });
344 342

  
345
  my $allow_pdf_export = $opts->{allow_pdf_export} && (-x $main::html2ps_bin) && (-x $main::ghostscript_bin);
343
  my $allow_pdf_export = $opts->{allow_pdf_export};
346 344

  
347 345
  eval { require PDF::API2; require PDF::Table; };
348 346
  $allow_pdf_export |= 1 if (! $@);
......
602 600
  return $allowed_paper_sizes{$requested_paper_size} ? $requested_paper_size : $default_paper_size;
603 601
}
604 602

  
605
sub render_pdf_with_html2ps {
606
  my $self      = shift;
607
  my $variables = $self->prepare_html_content();
608
  my $form      = $self->{form};
609
  my $myconfig  = $self->{myconfig};
610
  my $opt       = $self->{options}->{pdf_export};
611

  
612
  my $opt_number     = $opt->{number}                     ? 'number : 1'    : '';
613
  my $opt_landscape  = $opt->{orientation} eq 'landscape' ? 'landscape : 1' : '';
614

  
615
  my $opt_paper_size = $self->verify_paper_size($opt->{paper_size}, 'a4');
616

  
617
  my $html2ps_config = <<"END"
618
\@html2ps {
619
  option {
620
    titlepage: 0;
621
    hyphenate: 0;
622
    colour: 1;
623
    ${opt_landscape};
624
    ${opt_number};
625
  }
626
  paper {
627
    type: ${opt_paper_size};
628
  }
629
  break-table: 1;
630
}
631

  
632
\@page {
633
  margin-top:    $opt->{margin_top}cm;
634
  margin-left:   $opt->{margin_left}cm;
635
  margin-bottom: $opt->{margin_bottom}cm;
636
  margin-right:  $opt->{margin_right}cm;
637
}
638

  
639
BODY {
640
  font-family: Helvetica;
641
  font-size:   $opt->{font_size}pt;
642
}
643

  
644
END
645
  ;
646

  
647
  my $printer_command;
648
  if ($opt->{print} && $opt->{printer_id}) {
649
    $form->{printer_id} = $opt->{printer_id};
650
    $form->get_printer_code($myconfig);
651
    $printer_command = $form->{printer_command};
652
  }
653

  
654
  my $cfg_file_name = Common::tmpname() . '-html2ps-config';
655
  my $cfg_file      = IO::File->new($cfg_file_name, 'w') || $form->error($locale->text('Could not write the html2ps config file.'));
656

  
657
  $cfg_file->print($html2ps_config);
658
  $cfg_file->close();
659

  
660
  my $html_file_name = Common::tmpname() . '.html';
661
  my $html_file      = IO::File->new($html_file_name, 'w');
662

  
663
  if (!$html_file) {
664
    unlink $cfg_file_name;
665
    $form->error($locale->text('Could not write the temporary HTML file.'));
666
  }
667

  
668
  $html_file->print($form->parse_html_template($self->{options}->{pdf_template}, $variables));
669
  $html_file->close();
670

  
671
  my $cmdline =
672
    "\"${main::html2ps_bin}\" -f \"${cfg_file_name}\" \"${html_file_name}\" | " .
673
    "\"${main::ghostscript_bin}\" -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=${opt_paper_size} -sOutputFile=- -c .setpdfwrite -";
674

  
675
  my $gs = IO::File->new("${cmdline} |");
676
  if ($gs) {
677
    my $content;
678

  
679
    if (!$printer_command) {
680
      my $filename = $self->get_attachment_basename();
681
      print qq|content-type: application/pdf\n|;
682
      print qq|content-disposition: attachment; filename=${filename}.pdf\n\n|;
683

  
684
      while (my $line = <$gs>) {
685
        print $line;
686
      }
687

  
688
    } else {
689
      while (my $line = <$gs>) {
690
        $content .= $line;
691
      }
692
    }
693

  
694
    $gs->close();
695
    unlink $cfg_file_name, $html_file_name;
696

  
697
    if ($printer_command && $content) {
698
      $self->_print_content('printer_command' => $printer_command,
699
                            'content'         => $content,
700
                            'copies'          => $opt->{copies});
701
      $form->{report_generator_printed} = 1;
702
    }
703

  
704
  } else {
705
    unlink $cfg_file_name, $html_file_name;
706
    $form->error($locale->text('Could not spawn html2ps or GhostScript.'));
707
  }
708
}
709

  
710 603
sub _print_content {
711 604
  my $self   = shift;
712 605
  my %params = @_;
......
724 617

  
725 618
  eval { require PDF::API2; require PDF::Table; };
726 619

  
727
  if ($@) {
728
    return $self->render_pdf_with_html2ps(@_);
729
  } else {
730
    return $self->render_pdf_with_pdf_api2(@_);
731
  }
620
  return $self->render_pdf_with_pdf_api2(@_);
732 621
}
733 622

  
734 623
sub unescape_string {
......
943 832

  
944 833
The template to be used for HTML reports. Default is 'report_generator/html_report'.
945 834

  
946
=item pdf_template
947

  
948
The template to be used for PDF reports. Default is 'report_generator/pdf_report'.
949

  
950 835
=back
951 836

  
952 837
=head2 PDF Options

Auch abrufbar als: Unified diff