X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/42b702a6bbfdef8a094b1fafbdf205c986efd7be..0e65146d3e075b3ddd4eee951d6abfb90aca855d:/SL/ReportGenerator.pm diff --git a/SL/ReportGenerator.pm b/SL/ReportGenerator.pm index 2a40ab5e1..4a76a6c15 100644 --- a/SL/ReportGenerator.pm +++ b/SL/ReportGenerator.pm @@ -423,7 +423,7 @@ sub render_pdf_with_pdf_api2 { my $myconfig = $self->{myconfig}; my $opts = $self->{options}; - my $params = $opts->{pdf_export}; + my $pdfopts = $opts->{pdf_export}; my (@data, @column_props, @cell_props); @@ -504,19 +504,19 @@ sub render_pdf_with_pdf_api2 { my %supported_fonts = map { $_ => 1 } qw(courier georgia helvetica times verdana); - my $paper_size = defined $params->{paper_size} && defined $papersizes->{lc $params->{paper_size}} ? lc $params->{paper_size} : 'a4'; + my $paper_size = defined $pdfopts->{paper_size} && defined $papersizes->{lc $pdfopts->{paper_size}} ? lc $pdfopts->{paper_size} : 'a4'; my ($paper_width, $paper_height); - if (lc $params->{orientation} eq 'landscape') { + if (lc $pdfopts->{orientation} eq 'landscape') { ($paper_width, $paper_height) = @{$papersizes->{$paper_size}}[1, 0]; } else { ($paper_width, $paper_height) = @{$papersizes->{$paper_size}}[0, 1]; } - my $margin_top = _cm2bp($params->{margin_top} || 1.5); - my $margin_bottom = _cm2bp($params->{margin_bottom} || 1.5); - my $margin_left = _cm2bp($params->{margin_left} || 1.5); - my $margin_right = _cm2bp($params->{margin_right} || 1.5); + my $margin_top = _cm2bp($pdfopts->{margin_top} || 1.5); + my $margin_bottom = _cm2bp($pdfopts->{margin_bottom} || 1.5); + my $margin_left = _cm2bp($pdfopts->{margin_left} || 1.5); + my $margin_right = _cm2bp($pdfopts->{margin_right} || 1.5); my $table = PDF::Table->new(); my $pdf = PDF::API2->new(); @@ -524,16 +524,16 @@ sub render_pdf_with_pdf_api2 { $pdf->mediabox($paper_width, $paper_height); - my $font = $pdf->corefont(defined $params->{font_name} && $supported_fonts{lc $params->{font_name}} ? ucfirst $params->{font_name} : 'Verdana', + my $font = $pdf->corefont(defined $pdfopts->{font_name} && $supported_fonts{lc $pdfopts->{font_name}} ? ucfirst $pdfopts->{font_name} : 'Verdana', '-encoding' => $main::dbcharset || 'ISO-8859-15'); - my $font_size = $params->{font_size} || 7; + my $font_size = $pdfopts->{font_size} || 7; my $title_font_size = $font_size + 1; my $padding = 1; my $font_height = $font_size + 2 * $padding; my $title_font_height = $font_size + 2 * $padding; my $header_height = 2 * $title_font_height if ($opts->{title}); - my $footer_height = 2 * $font_height if ($params->{number}); + my $footer_height = 2 * $font_height if ($pdfopts->{number}); my $top_text_height = 0; @@ -582,7 +582,7 @@ sub render_pdf_with_pdf_api2 { foreach my $page_num (1..$pdf->pages()) { my $curpage = $pdf->openpage($page_num); - if ($params->{number}) { + if ($pdfopts->{number}) { my $label = $main::locale->text("Page #1/#2", $page_num, $pdf->pages()); my $text_obj = $curpage->text(); @@ -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 ($pdfopts->{print} && $pdfopts->{printer_id}) { + $form->{printer_id} = $pdfopts->{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' => $pdfopts->{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 { @@ -614,7 +631,7 @@ sub verify_paper_size { my $requested_paper_size = lc shift; my $default_paper_size = shift; - my %allowed_paper_sizes = map { $_ => 1 } qw(a3 a4 letter legal); + my %allowed_paper_sizes = map { $_ => 1 } qw(a3 a4 a5 letter legal); return $allowed_paper_sizes{$requested_paper_size} ? $requested_paper_size : $default_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;