X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FHelper%2FCreatePDF.pm;h=dda4b0df366562508e71639fe9093a78e694b6e2;hb=071e5546e649fc0108f64adfb1d0f8356dbe2716;hp=1baeada5882ef767916704af6a99b25e8496d0e6;hpb=b1cf0c0b1f64742c78426285b30cc399e10d2f0e;p=kivitendo-erp.git
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