[reportlab-users] Pagebreaks in ReportLab
Andy Robinson
reportlab-users@reportlab.com
Sat, 8 Feb 2003 23:29:24 -0000
> Hi there--I'm new to the reportlab library, and have a (hopefully) simple
> question:
>
> I've got a long document that I want to turn into a pdf, but I need to
> dynamically calculate where to put in page breaks. Is there some way from
> the reportlab library to report back to me when the cursor has
> reached the
> bottom of the page as a result of applying a textblock? Or do I have to
> precalculate the size of a text block, and then figure out if I need to
> split it across a page break?
>
> Thanks,
> --Steve
If you are using the Canvas class, it's your job. If you graduate
to Platypus (User Guide chapter 5 onwards), the model basically
generates events as it moves down the page, and moves to new
pages or columns for you. You just create a list of paragraphs,
images and other things and it flows them into the templates,
just like a word processor or DTP package.
Contrast the two scripts demos/odyssey/odyssey.py, which
handles flow down the page itself, and ..../fodyssey.py
which is a flowing version.
There's quite a few objects involved and the manual, while
technically correct, does not 'teach' this in the best order.
The fastest way of all to learn Platypus is actually to
download our full bundle and play with Report Markup
Language (tm) and RML2PDF, or glance at the sample files.
RML is basically a thin translation of the Platypus object
model into XML, but a heck of a lot more readable than a big
Python script constructing hundreds of objects. Even for
Python programmers :-)
Thanks,
Andy