views:

9589

answers:

13

What is a good tool for PDF report generation in Python? I've checked out ReportLab, but it seems to be awfully low-level for what I want to do. My current hunch is to call TeX on the command-line and let it produce the PDF, but if there is something that is easier to work with (and looks professional - We'll send this to customers) I'd very much like a prod in the right direction.

+4  A: 

I use pisa to generate PDF's from html files (which in turn get generated using xslt). It is very easy to use, but the official site is online last time i checked.

pisa is based on Reportlab. Demo site at http://www.htmltopdf.org/demo
gimel
This is really nice and convenient. For Hardy users, you cannot install the latest version, due to missing dependences (if you install everything else from Hardy repositories). Just use 3.0.24 which you can download and install with:sudo easy_install http://pypi.python.org/packages/2.5/p/pisa/pisa-3.0.24-py2.5.egg#md5=506c321e8125bf16bf70a3fe48624101
Davide
+1  A: 

If you don't like ReportLab I would suggest generating HTML - there are dozens of ways to do this and converting to PDF for final output (html2pdf for example).

mmaibaum
+1  A: 

You can create PDFs easily (in my opinion) with just a Cairo binding.

Sure, it is low level: you don't have a GUI form editor and need to calculate coordinates by hand. But it also is extremely lightweight and direct; you have absolute control. Doing it via HTML does not give you that.

The outcome looks great and is very tiny file size wise.

akauppi
I'm also interested in this question. Any chance of further details or a link regarding Cairo binding? I believe this is related to Lua or are you referring to something else. Thanks!
Jarod Elliott
Sorry my initial search results pointed at Lua but Cairo seems to be a graphics library. Assuming i've found the right thing (http://www.cairographics.org) it looks promising. +1
Jarod Elliott
I've also had good results with cairo, I've used it plus Cairo Plot to do plotting. https://launchpad.net/cairoplot
Aaron Maenpaa
I have nothing against cairo but this doesn't really answer the question for higher level report generation.
Toni Ruža
To Jarod: I'm indeed using Lua but thought not to mention, since it's a Python thread. :) The binding I use is Lua oocairo (http://www.daizucms.org/lua/library/oocairo/) , but there are -unfortunately- others. For Python, I think the situation is less fragmented http://www.cairographics.org/pycairo
akauppi
To Toni: I know, and I did mention in my comment that the solution is low level. Personally, I'd like to have a programmable PDF form editor where field values can be thrown in. But then again for my needs Cairo+Lua was enough.
akauppi
+9  A: 

I'm a big fan of pod. Design your report templates in open office writer (or ms word + sun's odf plugin) and then combine it with your data in a simple and flexible way. Very abstract and of course just a few lines of code.

You can generate odt documents this way with no external dependencies, for pdf generation you need to have open office running in server mode.

Toni Ruža
+1  A: 

You might also find this discussion helpful.

Onorio Catenacci
Although he said He's looked at reportlab.
ConcernedOfTunbridgeWells
There were some other tools mentioned. And I did say "might" :-)
Onorio Catenacci
I was about to ask how your project was going but I think it might be a bit off-topic to discuss another posting entirely in a thread on this one ;-)
ConcernedOfTunbridgeWells
+2  A: 

Is it feasible to generate your report content as reStructuredText? If so, check out the rst2pdf project.

Disclaimer: I have not used rst2pdf myself.

codeape
I also like reST, but the general work flow is reST -> LaTeX -> PDF. Though it looks like we're trying to avoid a LaTeX intermediary.
Aaron Maenpaa
I have used rst2pdf, and it does cut out the LaTeX step (although the output won't look *quite* as good as output going through LaTeX.) Probably would be ok for basic reports, but tables and layout aren't really the strong suit of reST.
technomalogical
+2  A: 

I would second mmaibaum's suggestion of generating HTML. It, along with CSS, will allow for much better positioning and layout. You can then use an HTML->PDF engine, such as PrinceXML (not free, but the output is amazing... actually there is a free version but it will put a PrinceXML logo on at least one of the pages) or an XML/XHTML->XSL-FO->PDF engine, such as CSSToXSLFO. This second option offers a bit more flexability, but you'll still need to choose an XSL-FO processor to turn this intermediate output into a PDF. Fop from the Apache project is a free one, but I can't vouch for how good the output is.

technomalogical
+1  A: 

I worked on a system years ago that used ReportLab. It really wasn't too bad. All of our reports were pretty much of the same style so I created a base class that handled most of the formatting. The only thing sub classes had to do was set some properties and hand the data over to the base class. It worked out pretty well. After I did the ground work another programmer was able to come behind me and bang out a couple dozen reports in a couple weeks with no prior Python experience. So if most of your reports fit one or two formats using ReportLab should just require some up front work and then the rest is drudgery.

Sam Corder
+2  A: 

The only reason not to use LaTeX in this layer is that the installation is large and unwieldy, particularly on Windows. You are not going to get a reporting engine without either having a formatting system or working in low level graphics primitives.

If you want a higher level formatting toolkit that's a bit more lightweight than LaTeX you might look at Lout.

ConcernedOfTunbridgeWells
LaTeX instalations do not have to be large. The full tex-life is large, but I used LateX on a PC-AT with a 2M-Byte ram-disk, and used it from there. 20 years later it has grown of course, but you can eliminate mos of what ou don't need
Stephan Eggermont
+7  A: 

When you looked at ReportLab, did you check out the Platypus section? It's really very easy to use (Platypus is high-level, whereas pdfgen is fairly low-level). There's a good "Hello World" example in the developer's FAQ.

Tony Meyer
+6  A: 

Take a look at Sphinx. A lot of Python projects are starting to use Sphinx, including Python itself. You type your documentation in reStructuredText, and get good-looking HTML and PDF output. Now that Matplotlib is using Sphinx, it even has a TeX-like equation formatting engine; see this pdf file for some more information.

Jouni K. Seppänen
Sphinx seems to use LaTex and he said that he prefer not to use LaTex
Davide
My impression is that his problem with TeX is ease of use - and while Sphinx does use LaTeX as the intermediate format for producing PDF, it generates all of it from the reStructuredText sources, so the user doesn't have to deal with LaTeX directly.But, yeah, it would be nice to have a ReportLabs backend for Sphinx so there would be no intermediate format where things can go wrong. In principle it should not be too hard, since Sphinx can already generate nice HTML, with mathematical formulas thanks to the Matplotlib mathtext engine.
Jouni K. Seppänen
FYI, the rst2pdf package now provides such a ReportLab builder for Sphinx
Kevin Horn
A: 

I recommend you take another look at ReportLab. It has high-level constructs for page layout and "flowing" text, images, frames etc. It also has a nice styles system and, most importantly, a nice python API. Sure, it also provides access to low-level pdf, but you don't need to use this until you need it.

Of the other suggestions, they mostly suggest using some other format as an intermediary. This doesn't really help you. It just pushes the problem to finding a good library for writing the intermediate format.

I've also tried the Eclipse "BIRT" report generator as another OSS reporting tool but it was hard to learn, a resource hog and a pain to deploy. Python + ReportLab was way easier.

bc
A: 

There is also PyReport, but that uses Latex for pdf-generation.

Space_C0wb0y