[reportlab-users] Generating PDF From DB Query

CLIFFORD ILKAY reportlab-users@reportlab.com
Tue, 10 Aug 2004 03:23:14 -0400


At 02:50 AM 10/08/2004 -0400, CLIFFORD ILKAY wrote:
>Hello all,
>
>I am using the more complex recipe at 
><http://wiki.w4py.org/pdfcreationwithreportlab.html>. I have that example 
>working but there was one mistake in the code. The last line should be 
>buffer.close(), not pdf.close(). Anyway, now I am trying to populate the 
>table from the result of a SQLObject <http://sqlobject.org> query like so:
>
>         people = Person.select(orderBy=Person.q.lastName)
>         tdata = []
>         row = []
>         for thePerson in people:
>             row = [thePerson.firstName, thePerson.lastName]
>             tdata.append(row)
>         t = Table(tdata, colwidths, rowheights)
>         t.setStyle(GRID_STYLE)
>         Story.append(t)

The problem was that rowheights was defined as a list of four elements. 
Anything less or greater than four rows would throw an exception. I just 
commented out the rowheights assignment and got rid of it in the Table(...) 
line. It worked. According to the docs, rowheight is calculated 
automatically if it is not explicitly stated anyway, though I am not sure 
if there is an adverse effect on performance.

According to an old message in the archives from Andy Robinson, he 
recommended that one should add 1000 tables of one row rather than one 
table of 1000 rows to prevent RL from having to recalculate the size of the 
remaining rows to be printed every time the table is split. I will now try 
to do that as opposed to the way that I am doing it above.

Regards,

Clifford Ilkay
Dinamis Corporation
3266 Yonge Street, Suite 1419
Toronto, Ontario
Canada M4N 3P6

Tel: 416-410-3326