X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FHelper%2FCreatePDF.pm;h=dda4b0df366562508e71639fe9093a78e694b6e2;hb=f93577f6c5cd7dd1d1d425f6951c1aa16f1d2e8a;hp=8d36eb74920a1871460e139379e8082bb7618b4b;hpb=e42233910a57d39f3ccef150db1212f7ecb7fb30;p=kivitendo-erp.git
diff --git a/SL/Helper/CreatePDF.pm b/SL/Helper/CreatePDF.pm
index 8d36eb749..dda4b0df3 100644
--- a/SL/Helper/CreatePDF.pm
+++ b/SL/Helper/CreatePDF.pm
@@ -28,31 +28,42 @@ 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->{format} = 'pdf';
+ $form->{$_} = $vars->{$_} for keys %{ $vars };
+ $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 $vars = $params{variables} || {};
- $form->{$_} = $vars->{$_} for keys %{ $vars };
-
- 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,
);
- my $parser = SL::Template::LaTeX->new(
- $form->{IN},
- $form,
- \%::myconfig,
- $userspath,
+ $form->{tmpfile} = $tmpfile;
+
+ my $parser = SL::Template::create(
+ type => ($params{template_type} || 'LaTeX'),
+ source => $form->{IN},
+ form => $form,
+ myconfig => \%::myconfig,
+ userspath => $userspath,
);
my $result = $parser->parse($temp_fh);
@@ -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