X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FHelper%2FCreatePDF.pm;h=555e75d7374c16b5b00b27bf85948e60f14d844f;hb=bdd1d7ea5dbe81ef852041c7517747ae7a404d03;hp=10618b21466ee521b2d81f25624f49983ab5ba46;hpb=f4958a2b79ab78d5b04257f7340c786fef526de7;p=kivitendo-erp.git diff --git a/SL/Helper/CreatePDF.pm b/SL/Helper/CreatePDF.pm index 10618b214..555e75d73 100644 --- a/SL/Helper/CreatePDF.pm +++ b/SL/Helper/CreatePDF.pm @@ -29,7 +29,9 @@ sub create_pdf { my ($class, %params) = @_; my $userspath = $::lx_office_conf{paths}->{userspath}; + my $vars = $params{variables} || {}; my $form = Form->new(''); + $form->{$_} = $vars->{$_} for keys %{ $vars }; $form->{format} = 'pdf'; $form->{cwd} = getcwd(); $form->{templates} = $::instance_conf->get_templates; @@ -37,9 +39,6 @@ sub create_pdf { $form->{tmpdir} = $form->{cwd} . '/' . $userspath; my ($suffix) = $params{template} =~ m{\.(.+)}; - my $vars = $params{variables} || {}; - $form->{$_} = $vars->{$_} for keys %{ $vars }; - my $temp_fh; ($temp_fh, $form->{tmpfile}) = File::Temp::tempfile( 'kivitendo-printXXXXXX', @@ -153,3 +152,135 @@ sub find_template { } 1; +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::Helper::CreatePDF - A helper for creating PDFs from template files + +=head1 SYNOPSIS + + # Retrieve a sales order from the database and create a PDF for + # it: + my $order = SL::DB::Order->new(id => …)->load; + my $print_form = Form->new(''); + $print_form->{type} = 'invoice'; + $print_form->{formname} = 'invoice', + $print_form->{format} = 'pdf', + $print_form->{media} = 'file'; + + $order->flatten_to_form($print_form, format_amounts => 1); + $print_form->prepare_for_printing; + + my $pdf = SL::Helper::CreatePDF->create_pdf( + template => 'sales_order', + variables => $print_form, + ); + +=head1 FUNCTIONS + +=over 4 + +=item C + +Parses a LaTeX template file, creates a PDF for it and returns either +its content or its file name. The recognized parameters are: + +=over 2 + +=item * C