[reportlab-users] How to mix static positioning and flowables

1,256 views
Skip to first unread message

Mike Driscoll

unread,
Aug 7, 2013, 11:20:31 AM8/7/13
to reportl...@lists2.reportlab.com
Hi,

I have a project where I'm basically creating a document where the top half has to be positioned exactly and the second half is a table that can run multiple pages. I was doing the static part using Reportlab's canvas object, but I can't figure out how to make the table split across multiple pages if it gets too long.

All the resources I've found so far recommend using a Template like BaseDocTemplate, but I don't see any way to use that to mix the static content and the dynamic content on one page.

I have attached what I've come up with so far, but the table obviously doesn't split. Any help would be appreciated. Thanks!

-------------------
Mike Driscoll

Blog:   http://blog.pythonlibrary.org
multipage_test.py

Andy Robinson

unread,
Aug 7, 2013, 12:54:32 PM8/7/13
to reportlab-users
Does the static content
(a) only need to appear on Page 1?
(b) need to appear identically on every page?
(c) need to vary by page?

All of these are possible but would use different approaches..

- Andy
> _______________________________________________
> reportlab-users mailing list
> reportl...@lists2.reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
>



--
Andy Robinson
Managing Director
ReportLab Europe Ltd.
Thornton House, Thornton Road, Wimbledon, London SW19 4NG, UK
Tel +44-20-8405-6420
_______________________________________________
reportlab-users mailing list
reportl...@lists2.reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users

Mike Driscoll

unread,
Aug 7, 2013, 1:27:56 PM8/7/13
to reportlab-users
Hi Andy,

In this case, the static content only appears on the first page. The table can then continue for however many pages after that as needed. I do have an older project where I did have the same static stuff on each page with a flowing table across pages and sub-totals per page that I ended up writing a hack for. I'm trying not to do that for this one.

- Mike
--
-----------------

Mike Driscoll

unread,
Aug 8, 2013, 3:29:08 PM8/8/13
to reportlab-users
Hi,

I have been experimenting using the table and I notice that when I use table.drawOn(), it changes position depending on how many rows of data I pass the table. Why won't the table start at the position I'm passing it every single time?

Right now, my plan is to find out how many rows of data I can fit on the bottom half of the page and then add a check that says, if number of rows is greater than X, only pass X rows of data to the table and save the following rows into a new list. Then I'll add a page break, create a new table and pass it the new list. However since the table refuses to actually stay where I tell it, I'm not sure I can even use a table object at this point. Any suggestions?

- Mike

Robin Becker

unread,
Aug 19, 2013, 5:39:17 AM8/19/13
to reportlab-users
Mike,

flowables determine their height width etc etc in the wrap function and then a
framelike object is supposed to position the flowable in a top down fashion.
That means we have to adjust the y location based on the height of the flowable
see reportlab/platypus/frames.py near line 166

y -= h

effectively moves the draw location down the frame by the required height.

Our coordinates are standard y increases upwards, but page layout is like TV.


On 08/08/2013 20:29, Mike Driscoll wrote:
> Hi,
>
> I have been experimenting using the table and I notice that when I use
> table.drawOn(), it changes position depending on how many rows of data I
> pass the table. Why won't the table start at the position I'm passing it
> every single time?
>
> Right now, my plan is to find out how many rows of data I can fit on the
> bottom half of the page and then add a check that says, if number of rows
> is greater than X, only pass X rows of data to the table and save the
> following rows into a new list. Then I'll add a page break, create a new
> table and pass it the new list. However since the table refuses to actually
> stay where I tell it, I'm not sure I can even use a table object at this
> point. Any suggestions?
>
> - Mike
.......
--
Robin Becker

Mike Driscoll

unread,
Aug 19, 2013, 9:51:19 AM8/19/13
to Robin Becker, reportlab-users
Hi Robin,

I actually figured out a way to get this to work using a template. I ended up writing a tutorial about it since I'm guessing I'll probably end up needing to do this again some time in the future...and for all the other people who have to do this sort of thing. My tutorial is here: http://www.blog.pythonlibrary.org/2013/08/09/reportlab-how-to-combine-static-content-and-multipage-tables/

Thanks and have a great day!
Mike



On Mon, Aug 19, 2013 at 4:39 AM, Robin Becker <ro...@reportlab.com> wrote:
Mike,

flowables determine their height width etc etc in the wrap function and then a framelike object is supposed to position the flowable in a top down fashion. That means we have to adjust the y location based on the height of the flowable see reportlab/platypus/frames.py near line 166

           y -= h

effectively moves the draw location down the frame by the required height.

Our coordinates are standard y increases upwards, but page layout is like TV.



On 08/08/2013 20:29, Mike Driscoll wrote:
Hi,

I have been experimenting using the table and I notice that when I use
table.drawOn(), it changes position depending on how many rows of data I
pass the table. Why won't the table start at the position I'm passing it
every single time?

Right now, my plan is to find out how many rows of data I can fit on the
bottom half of the page and then add a check that says, if number of rows
is greater than X, only pass X rows of data to the table and save the
following rows into a new list. Then I'll add a page break, create a new
table and pass it the new list. However since the table refuses to actually
stay where I tell it, I'm not sure I can even use a table object at this
point. Any suggestions?

- Mike
.......
--
Robin Becker



Reply all
Reply to author
Forward
0 new messages