summaryrefslogtreecommitdiff
path: root/LedgerSMB/Template/PDF.pm
blob: 72c080c6062f76f480163522e24fd1e65f1df1c9 (plain)
  1. =head1 NAME
  2. LedgerSMB::Template::PDF Template support module for LedgerSMB
  3. =head1 METHODS
  4. =over
  5. =item get_template ($name)
  6. Returns the appropriate template filename for this format.
  7. =item preprocess ($vars)
  8. Currently does nothing.
  9. =item process ($parent, $cleanvars)
  10. Processes the template for PDF.
  11. =item postprocess ($parent)
  12. Currently does nothing.
  13. =back
  14. =head1 Copyright (C) 2007, The LedgerSMB core team.
  15. This work contains copyrighted information from a number of sources all used
  16. with permission.
  17. It is released under the GNU General Public License Version 2 or, at your
  18. option, any later version. See COPYRIGHT file for details. For a full list
  19. including contact information of contributors, maintainers, and copyright
  20. holders, see the CONTRIBUTORS file.
  21. =cut
  22. package LedgerSMB::Template::PDF;
  23. use Error qw(:try);
  24. use Template::Latex;
  25. sub get_template {
  26. my $name = shift;
  27. return "${name}.tex";
  28. }
  29. sub preprocess {
  30. my $rawvars = shift;
  31. my $vars;
  32. my $type = ref $rawvars;
  33. return $vars;
  34. }
  35. sub process {
  36. my $parent = shift;
  37. my $cleanvars = shift;
  38. my $template;
  39. $template = Template::Latex->new({
  40. LATEX_FORMAT => 'pdf',
  41. INCLUDE_PATH => $parent->{include_path},
  42. START_TAG => quotemeta('<?lsmb'),
  43. END_TAG => quotemeta('?>'),
  44. DELIMITER => ';',
  45. }) || throw Error::Simple Template::Latex->error();
  46. if (not $template->process(
  47. get_template($parent->{template}),
  48. $cleanvars, "$parent->{outputfile}.pdf", binmode => ':utf8')) {
  49. throw Error::Simple $template->error();
  50. }
  51. $parent->{mimetype} = 'application/pdf';
  52. }
  53. sub postprocess {
  54. my $parent = shift;
  55. $parent->{rendered} = "$parent->{outputfile}.pdf";
  56. return "$parent->{outputfile}.pdf";
  57. }
  58. 1;