[reportlab-users] Producing pages out of order - possible?

Andy Robinson andy at reportlab.com
Tue Apr 29 07:55:16 EDT 2008

> Paul Sleigh wrote:


> > G'day. I've got a project I wrote in PHP using an open source PDF

> > So, my question: can I do this using the ReportLab tool? If so, I think

> you've found a lifelong friend; if not, I fear I may have to come up with

> some other solution, and I'm running out of ideas.

It's fairly easy. There are two approaches.

(1) If, up front, you can work out how many pages the table of
contents will occupy
(e.g. by quickly counting chapters), then you can generate most of the document
in one pass, and on page 2 (or wherever you TOC goes) you put in an instruction


What this does can actually be defined later.

As you render the doc, you keep track of the pages you are on as you start
each chapter. Then, at the end of the document, you do

#various operations to draw the headings and page numbers

Acrobat Reader actually puts it all together for you. you just need
to define any referenced form before you save the canvas.

It's a bit fiddlier with flowing content, or if you calculate that you need more
than 1 page for the table of contents, but that's the essence of it and it lets
you do one forward pass at high speed.

Approach 2 used some crude reference objects we built which allow multi-pass
generation of flowing documents. This is under-documented and we have promised
Dinu to try and make a better high-level 'TableOfContents' flowable which wraps
it up, but haven't doe this yet.

Best Regards,

Andy Robinson
CEO/Chief Architect
ReportLab Europe Ltd.
165 The Broadway, Wimbledon, London SW19 1NE, UK
Tel +44-20-8544-8049

More information about the reportlab-users mailing list