Hello,
a while ago I've been talking about pango cairo and how to generate pdf with a couple of tables.
In the meantime I've worked on it, improving and enhancing new kinds of elements. This has lead to the creation of a small project, a library providing a simple framework for generating mostly PDF reports (I haven't tried to generate SVG or something else yet).
After a couple of release requests, I've found finally the time to publish a sort of working code.
Here's the git repository and here you can download the snapshot tarball.
Any patches welcome.
Showing posts with label pango. Show all posts
Showing posts with label pango. Show all posts
Tuesday, July 21, 2009
Wednesday, May 27, 2009
Render tables with pangocairo like reportlab
Hello,
lately I was wondering if there was any alternative to the well known reportlab python software for creating PDF reports. I immediately thought about Cairo. The only two problems are:
Here's the Pango tables code snippet containing the necessary classes for achieving the job. Notice that the methods in the snippet often make use of Pango units instead of pixels.
Here's the result test.pdf:

lately I was wondering if there was any alternative to the well known reportlab python software for creating PDF reports. I immediately thought about Cairo. The only two problems are:
- Cairo doesn't create multiple pages
- No support for creating tables containing text, necessary for table-based reports
I still can't realize how to achieve the first feature, but the second one could be solved using Pango layouts.
The idea is to create the cells of the table using such layouts, so that the text get wrapped etc.
Now let's use the Table class as follows: create a table with two rows and two columns, then show it twice with different background colors.
surface = cairo.PDFSurface ("test.pdf", 300, 400)
cr = cairo.Context (surface)
cr = pangocairo.CairoContext (cairo.Context (surface))
sizes = [pango.SCALE*12*10, pango.SCALE*12*10]
data = [["first test with pango tables", "seems to work correctly"],
["though it needs", "support for borders and spans"]]
table = Table (cr, sizes, data, pango.FontDescription ("Sans 12"))
cr.rectangle (0, 0, pango.PIXELS(table.get_width ()), pango.PIXELS(table.get_height()))
cr.set_source_rgb (0.8, 0.8, 0.8)
cr.fill ()
cr.set_source_rgb (0, 0, 0)
table.show_table (cr)
cr.translate (0, 200)
cr.rectangle (0, 0, pango.PIXELS(table.get_width ()), pango.PIXELS(table.get_height()))
cr.set_source_rgb (0.4, 0.5, 0.7)
cr.fill ()
cr.set_source_rgb (0, 0, 0)
table.show_table (cr)Here's the result test.pdf:

Subscribe to:
Posts (Atom)