Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f93577f6

Von Moritz Bunkus vor fast 10 Jahren hinzugefügt

  • ID f93577f6c5cd7dd1d1d425f6951c1aa16f1d2e8a
  • Vorgänger 71a4acd1
  • Nachfolger 7c54e92f

CreatePDF-Helfer: auch HTML aus HTML erzeugen können

Unterschiede anzeigen:

SL/Helper/CreatePDF.pm
28 28
sub create_pdf {
29 29
  my ($class, %params) = @_;
30 30

  
31
  return $class->create_parsed_file(
32
    format        => 'pdf',
33
    template_type => 'LaTeX',
34
    %params,
35
  );
36
}
37

  
38
sub create_parsed_file {
39
  my ($class, %params) = @_;
40

  
31 41
  my $userspath       = $::lx_office_conf{paths}->{userspath};
32 42
  my $vars            = $params{variables} || {};
33 43
  my $form            = Form->new('');
34 44
  $form->{$_}         = $vars->{$_} for keys %{ $vars };
35
  $form->{format}     = 'pdf';
45
  $form->{format}     = lc($params{format} || 'pdf');
36 46
  $form->{cwd}        = getcwd();
37 47
  $form->{templates}  = $::instance_conf->get_templates;
38 48
  $form->{IN}         = $params{template};
39 49
  $form->{tmpdir}     = $form->{cwd} . '/' . $userspath;
40 50
  my ($suffix)        = $params{template} =~ m{\.(.+)};
41 51

  
42
  my $temp_fh;
43
  ($temp_fh, $form->{tmpfile}) = File::Temp::tempfile(
52
  my ($temp_fh, $tmpfile) = File::Temp::tempfile(
44 53
    'kivitendo-printXXXXXX',
45 54
    SUFFIX => ".${suffix}",
46 55
    DIR    => $userspath,
47 56
    UNLINK => ($::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files})? 0 : 1,
48 57
  );
49 58

  
59
  $form->{tmpfile} = $tmpfile;
60

  
50 61
  my $parser  = SL::Template::create(
51
    type      => 'LaTeX',
62
    type      => ($params{template_type} || 'LaTeX'),
52 63
    source    => $form->{IN},
53 64
    form      => $form,
54 65
    myconfig  => \%::myconfig,
......
66 77
  }
67 78

  
68 79
  if (($params{return} || 'content') eq 'file_name') {
69
    my $new_name = $userspath . '/keep-' . $form->{tmpfile};
70
    rename $userspath . '/' . $form->{tmpfile}, $new_name;
80
    my $new_name = $userspath . '/keep-' . $tmpfile;
81
    rename $tmpfile, $new_name;
71 82

  
72 83
    $form->cleanup;
73 84

  
74 85
    return $new_name;
75 86
  }
76 87

  
77
  my $pdf = File::Slurp::read_file($userspath . '/' . $form->{tmpfile});
88
  my $content = File::Slurp::read_file($tmpfile);
78 89

  
79 90
  $form->cleanup;
80 91

  
81
  return $pdf;
92
  return $content;
82 93
}
83 94

  
84 95
sub merge_pdfs {
......
189 200
=item C<create_pdf %params>
190 201

  
191 202
Parses a LaTeX template file, creates a PDF for it and returns either
192
its content or its file name. The recognized parameters are:
203
its content or its file name. The recognized parameters are the same
204
as the ones for L</create_parsed_file> with C<format> and
205
C<template_type> being pre-set.
206

  
207
=item C<create_parsed_file %params>
208

  
209
Parses a template file and returns either its content or its file
210
name. The recognized parameters are:
193 211

  
194 212
=over 2
195 213

  
......
207 225
the PDF itself is returned and all temporary files have already been
208 226
deleted by L</create_pdf>.
209 227

  
228
=item * C<format> – optional, defaults to C<pdf> and determines the
229
output format. Can be set to C<html> for HTML output if
230
C<template_type> is set to C<HTML> as well.
231

  
232
=item * C<template_type> – optional, defaults to C<LaTeX> and
233
determines the template's format. Can be set to C<HTML> for HTML
234
output if C<format> is set to C<html> as well.
235

  
210 236
=back
211 237

  
212 238
=item C<find_template %params>

Auch abrufbar als: Unified diff