[reportlab-users] Multipage tables
Robin Becker
robin at reportlab.com
Fri Oct 1 06:29:25 EDT 2010
On 30/09/2010 23:48, Juan Efren Castillo wrote:
> Thanks for your response, I am doing this way:
>
> canvasTable = Table(data, colWidths=tuple(widths), rowHeights=None)
> w,h = canvasTable.wrapOn(p,3*72,2*72)
> canvasTable.drawOn(p, t.x, page_size[1]-t.y-h, 0)
>
> So what I understand is to do a wrap for each page ?
>
> On Thu, Sep 30, 2010 at 6:58 AM, Robin Becker<robin at reportlab.com> wrote:
>
>> On 30/09/2010 02:29, Juan Efren Castillo wrote:
>>
>>> I have a dynamically generated table how ever when the number of rows is
>>> big, they just got printed outside my canvas, how can I print these rows
>>> in
>>> other page ?
>>> Thanks in advance. :)
>>>
>> .......
>> you don't say exactly how you're drawing the table. Since Tables are
>> Flowables the doctemplate classes handle them properly. If you're trying to
>> draw them directly onto a canvas then you need to emulate the way that the
>> doctemplate does it when the flowables are added to a frame.
>>
>> table.wrap(availableWidth,availableHeight) --> requiredWidth,
>> requiredHeight
>>
>> table.split(availableWidth,availableHeight) --> list of flowables, the
>> first of which is supposed to fit into the available space.
>>
>>
>> --
>> Robin Becker
>>
>
>
>
It's not exactly clear how the table content relates to the page since t is not
shown.
The obvious way to split up a table into chunks is then going to be like this
T = [Table(data, colWidths=tuple(widths), rowHeights=None)]
tH = xxx #desired size per page
tW = xxx
x = xxx #desired table location on the page
y = xxx
while T:
t = T.pop(0)
w,h = t.wrapOn(canv,tW,tH)
if w>tW:
raise ValueError('table too wide')
if h>tH:
S = t.splitOn(canv,tW,tH)
if not S:
raise ValueError('cannot split table')
#S[0] should fit
t = S.pop(0)
t.drawOn(canv, x, y, 0)
T[0:0] = S #insert unused stuff back into T
canv.showPage()
else:
#whole table fits do that
t.drawOn(canv, x, y, 0)
or something similar with variation in positions/sizes etc etc
--
Robin Becker
More information about the reportlab-users
mailing list