Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a02d6065

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID a02d6065bf595a427e41d509b2d1d6bbd9138c7b
  • Vorgänger f4958a2b
  • Nachfolger ceb551dd

CreatePDF-Helfer: Dokumentation

Unterschiede anzeigen:

SL/Helper/CreatePDF.pm
153 153
}
154 154

  
155 155
1;
156
__END__
157

  
158
=pod
159

  
160
=encoding utf8
161

  
162
=head1 NAME
163

  
164
SL::Helper::CreatePDF - A helper for creating PDFs from template files
165

  
166
=head1 SYNOPSIS
167

  
168
  # Retrieve a sales order from the database and create a PDF for
169
  # it:
170
  my $order               = SL::DB::Order->new(id => …)->load;
171
  my $print_form          = Form->new('');
172
  $print_form->{type}     = 'invoice';
173
  $print_form->{formname} = 'invoice',
174
  $print_form->{format}   = 'pdf',
175
  $print_form->{media}    = 'file';
176

  
177
  $order->flatten_to_form($print_form, format_amounts => 1);
178
  $print_form->prepare_for_printing;
179

  
180
  my $pdf = SL::Helper::CreatePDF->create_pdf(
181
    template  => 'sales_order',
182
    variables => $print_form,
183
  );
184

  
185
=head1 FUNCTIONS
186

  
187
=over 4
188

  
189
=item C<create_pdf %params>
190

  
191
Parses a LaTeX template file, creates a PDF for it and returns either
192
its content or its file name. The recognized parameters are:
193

  
194
=over 2
195

  
196
=item * C<template> – mandatory. The template file name relative to
197
the users' templates directory. Must be an existing file name,
198
e.g. one retrieved by L</find_template>.
199

  
200
=item * C<variables> – optional hash reference containing variables
201
available to the template.
202

  
203
=item * C<return> – optional scalar containing either C<content> (the
204
default) or C<file_name>. If it is set to C<file_name> then the file
205
name of the temporary file containing the PDF is returned, and the
206
caller is responsible for deleting it. Otherwise a scalar containing
207
the PDF itself is returned and all temporary files have already been
208
deleted by L</create_pdf>.
209

  
210
=back
211

  
212
=item C<find_template %params>
213

  
214
Searches the user's templates directory for a template file name to
215
use. The file names considered depend on the parameters; they can
216
contain a template base name and suffixes for email, language and
217
printers. As a fallback the name C<default.$extension> is also
218
considered.
219

  
220
The return value depends on the context. In scalar context the
221
template file name that matches the given parameters is returned. It's
222
a file name relative to the user's templates directory. If no template
223
file is found then C<undef> is returned.
224

  
225
In list context the first element is the same value as in scalar
226
context. Additionally a list of considered template file names is
227
returned.
228

  
229
The recognized parameters are:
230

  
231
=over 2
232

  
233
=item * C<name> – mandatory. The template's file name basis
234
without any additional suffix or extension, e.g. C<sales_quotation>.
235

  
236
=item * C<extension> – optional file name extension to use without the
237
dot. Defaults to C<tex>.
238

  
239
=item * C<email> – optional flag indicating whether or not the
240
template is to be sent via email. If set to true then template file
241
names containing C<_email> are considered as well.
242

  
243
=item * C<language> and C<language_id> – optional parameters
244
indicating the language to be used. C<language> can be either a string
245
containing the language code to use or an instance of
246
C<SL::DB::Language>. C<language_id> can contain the ID of the
247
C<SL::DB:Language> instance to load and use. If given template file
248
names containing C<_language_template_code> are considered as well.
249

  
250
=item * C<printer> and C<printer_id> – optional parameters indicating
251
the printer to be used. C<printer> can be either a string containing
252
the printer code to use or an instance of
253
C<SL::DB::Printer>. C<printer_id> can contain the ID of the
254
C<SL::DB:Printer> instance to load and use. If given template file
255
names containing C<_printer_template_code> are considered as well.
256

  
257
=back
258

  
259
=item C<merge_pdfs %params>
260

  
261
Merges two or more PDFs into a single PDF by using the external
262
application ghostscript.
263

  
264
The recognized parameters are:
265

  
266
=over 2
267

  
268
=item * C<file_names> – mandatory array reference containing the file
269
names to merge.
270

  
271
=back
272

  
273
Note that this function relies on the presence of the external
274
application ghostscript. The executable to use is configured via
275
kivitendo's configuration file setting C<application.ghostscript>.
276

  
277
=back
278

  
279
=head1 BUGS
280

  
281
Nothing here yet.
282

  
283
=head1 AUTHOR
284

  
285
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
286

  
287
=cut

Auch abrufbar als: Unified diff