Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make PDF reports in Perl?

All the PDF libraries for Perl seem a bit barbaric -- stuck in the 1980's. You have to specify PostScript points to do layout. Java has JasperReports, Ruby has Prawn, and Python has ReportLab. Is there a non-extinct library/module that will let me make a nice looking PDF in less than a week of coding? (I'm a little frustrated by PDF::API2, PDF::Table, etc.) I don't want to generate HTML and convert it. Perl is ideal for reporting, but the main report file format is not available in a usable way. What libraries do people use?

I need:

  • tables
  • charts (Images)
  • color
  • formatting (ideally automatic, not pixel by pixel)
  • headers / footers

I'm slightly open to wrapping external (non-Perl) open source tools, if absolutely needed. But not really interested in a major Java server approach. For the bounty, I want a pure Perl approach, since I want to run this on a server that I can't add more than modules to. If you have a public example that works well, please point me to it.

like image 474
sventechie Avatar asked Sep 23 '11 21:09

sventechie


1 Answers

Using Perl, generate LaTeX, perhaps using Template::Toolkit, then call the compiler, either TeXLive or MikTeX or whatever distribution you need for your OS. There is an extension called Template::LaTeX, though you probably don't need it, which manages the build process.

LaTeX has support for all the things you need. Tables get a little interesting but there are some modern table packages which ease things (I think that its called ltxtable). For charts (do you mean diagrams) there is a sub language called TikZ which is spectacularly powerful.

This really is a very easy workflow, especially if you want the results to be similar every time (i.e. can use a template). In fact it really is not unlike creating HTML from a template and serving it to a browser.

Another benefit of this is that the template (and prepared source) will be portable should you need to build a report in another language.

like image 200
Joel Berger Avatar answered Oct 18 '22 12:10

Joel Berger