From f93577f6c5cd7dd1d1d425f6951c1aa16f1d2e8a Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 12 Jan 2015 16:44:11 +0100 Subject: [PATCH] =?utf8?q?CreatePDF-Helfer:=20auch=20HTML=20aus=20HTML=20e?= =?utf8?q?rzeugen=20k=C3=B6nnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Helper/CreatePDF.pm | 44 +++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/SL/Helper/CreatePDF.pm b/SL/Helper/CreatePDF.pm index 1baeada58..dda4b0df3 100644 --- a/SL/Helper/CreatePDF.pm +++ b/SL/Helper/CreatePDF.pm @@ -28,27 +28,38 @@ our %EXPORT_TAGS = ( sub create_pdf { my ($class, %params) = @_; + return $class->create_parsed_file( + format => 'pdf', + template_type => 'LaTeX', + %params, + ); +} + +sub create_parsed_file { + 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->{format} = lc($params{format} || 'pdf'); $form->{cwd} = getcwd(); $form->{templates} = $::instance_conf->get_templates; $form->{IN} = $params{template}; $form->{tmpdir} = $form->{cwd} . '/' . $userspath; my ($suffix) = $params{template} =~ m{\.(.+)}; - my $temp_fh; - ($temp_fh, $form->{tmpfile}) = File::Temp::tempfile( + my ($temp_fh, $tmpfile) = File::Temp::tempfile( 'kivitendo-printXXXXXX', SUFFIX => ".${suffix}", DIR => $userspath, UNLINK => ($::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files})? 0 : 1, ); + $form->{tmpfile} = $tmpfile; + my $parser = SL::Template::create( - type => 'LaTeX', + type => ($params{template_type} || 'LaTeX'), source => $form->{IN}, form => $form, myconfig => \%::myconfig, @@ -66,19 +77,19 @@ sub create_pdf { } if (($params{return} || 'content') eq 'file_name') { - my $new_name = $userspath . '/keep-' . $form->{tmpfile}; - rename $userspath . '/' . $form->{tmpfile}, $new_name; + my $new_name = $userspath . '/keep-' . $tmpfile; + rename $tmpfile, $new_name; $form->cleanup; return $new_name; } - my $pdf = File::Slurp::read_file($userspath . '/' . $form->{tmpfile}); + my $content = File::Slurp::read_file($tmpfile); $form->cleanup; - return $pdf; + return $content; } sub merge_pdfs { @@ -189,7 +200,14 @@ SL::Helper::CreatePDF - A helper for creating PDFs from template files =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: +its content or its file name. The recognized parameters are the same +as the ones for L with C and +C being pre-set. + +=item C + +Parses a template file and returns either its content or its file +name. The recognized parameters are: =over 2 @@ -207,6 +225,14 @@ caller is responsible for deleting it. Otherwise a scalar containing the PDF itself is returned and all temporary files have already been deleted by L. +=item * C – optional, defaults to C and determines the +output format. Can be set to C for HTML output if +C is set to C as well. + +=item * C – optional, defaults to C and +determines the template's format. Can be set to C for HTML +output if C is set to C as well. + =back =item C -- 2.20.1