Invoicing with ReportLab (A bit of sample code for the curious...)
Last update on .
Have been working with the open-source ReportLab package to create invoices the last few days. The results aren't what I would consider beautiful yet, but they are a reasonable layout format for an invoice. Since it took me a bit of time to set it up I figure I'll share it with the world.
The code assumes that you have an "invoice" object with multiple streams, those streams providing iteration methods that allow you to find the individual line-items within the stream, as well as the discounts applied post-tax to the stream. A total of all charges is presented on the first page of the invoice.
You can see code in there to produce alternate-line colours (that is, alternating line-items are shown in different background colours). There's also code for doing column-spanning, and column alignment. There are two headers, a larger first-page header and a smaller second-page header, those aren't handled particularly well at the moment, they should be auto-expanding so that if the client address is short the main frame is further up the page.
The entire thing needs some refactoring, but oh well, it should give an idea of how ReportLab works. Enjoy.
Comments are closed.
Pingbacks are closed.
Graham Dumpleton on 08/14/2006 9:51 p.m. #
Worth looking at if you are doing this is RML2PDF from 'http://www.openreport.org'. This uses reportlab to go from a XML based description of your document to PDF. The company behind reportlab has their own commercial version of this, but the one I reference is an Open Source equivalent. The RML description file has very similar stuff to your code as the RML file in effect triggers calls of the class in reportlab when it is being processed. Having constructed the RML, you just need to use a template substitution mechanism of your choice to replace the variable bits before passing it through RML2PDF. You can find documentation on the RML format from the commercial reportlab site at 'http://www.reportlab.com/rml_index.html'.
Jeff Kowalczyk on 08/15/2006 7:53 a.m. #
For large-scale tabular reporting, you may also want to investigate rlib http://rlib.sicompos.com (GPL)<br />
rlib's greenbar/lineprinter-style PDF, HTML, TXT, CSV rendering seems applicable to accounting and line-of-business applications. It is a C library with bindings for python, etc. The dependency tree isn't onerous.
Alan Green on 08/17/2006 6:09 p.m. #
Every time I start coding against a PDF formatting libraries, I feel like I'm reinventing a browser renderer. Font styles, postioning, linebreaks, tables, background colors, images - it's all there.
Jason Imison on 07/30/2007 4:56 p.m. #
Pisa seems very good from what I've seen so far ( all of 5 minutes )<br />
It uses ReportLab behind the scenes to create PDFs from a subset of HTML / CSS<br />
Dave on 08/24/2007 6:44 a.m. #
Is this code the same as:<br />
Mike Fletcher on 08/24/2007 1:23 p.m. #
Looks like a fork of some type. Doesn't look to be hooked up to anything, though.