X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FHelper%2FCreatePDF.pm;h=d85ad7d8afaca10b60932de4a0e50e4f6b279135;hb=0b33cc602d717933791d06cb64f65dea2a7c2354;hp=1baeada5882ef767916704af6a99b25e8496d0e6;hpb=b1cf0c0b1f64742c78426285b30cc399e10d2f0e;p=kivitendo-erp.git
diff --git a/SL/Helper/CreatePDF.pm b/SL/Helper/CreatePDF.pm
index 1baeada58..d85ad7d8a 100644
--- a/SL/Helper/CreatePDF.pm
+++ b/SL/Helper/CreatePDF.pm
@@ -6,6 +6,7 @@ use Carp;
use Cwd;
use English qw(-no_match_vars);
use File::Slurp ();
+use File::Spec ();
use File::Temp ();
use List::MoreUtils qw(uniq);
use List::Util qw(first);
@@ -28,31 +29,44 @@ our %EXPORT_TAGS = (
sub create_pdf {
my ($class, %params) = @_;
+ return __PACKAGE__->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 $tmpdir = $form->{tmpdir};
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,
+ DIR => $form->{tmpdir},
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,
- userspath => $userspath,
+ userspath => $tmpdir,
+ variable_content_types => $params{variable_content_types},
);
my $result = $parser->parse($temp_fh);
@@ -65,20 +79,26 @@ sub create_pdf {
die $parser->get_error;
}
+ # SL::Template:** modify $form->{tmpfile} by removing its
+ # $form->{userspath} prefix. They also store the final file's actual
+ # file name in $form->{tmpfile} â but it is now relative to
+ # $form->{userspath}. Other modules return the full file nameâ¦
+ my ($volume, $directory, $file_name) = File::Spec->splitpath($form->{tmpfile});
+ my $full_file_name = File::Spec->catfile($tmpdir, $file_name);
if (($params{return} || 'content') eq 'file_name') {
- my $new_name = $userspath . '/keep-' . $form->{tmpfile};
- rename $userspath . '/' . $form->{tmpfile}, $new_name;
+ my $new_name = File::Spec->catfile($tmpdir, 'keep-' . $form->{tmpfile});
+ rename $full_file_name, $new_name;
$form->cleanup;
return $new_name;
}
- my $pdf = File::Slurp::read_file($userspath . '/' . $form->{tmpfile});
+ my $content = File::Slurp::read_file($full_file_name);
$form->cleanup;
- return $pdf;
+ return $content;
}
sub merge_pdfs {
@@ -189,7 +209,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 +234,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