[reportlab-users] Reportlab performance

Andy Robinson andy at reportlab.com
Wed May 12 10:51:54 EDT 2010

On 12 May 2010 14:55, Henning von Bargen <H.vonBargen at t-p.com> wrote:

> The idea is that you tell ReportLab in advance that you expect

> the TOC needs N pages (you can compute that in your special case,

> since you need one TOC row per article).

I have done some experiments and am checking in a small update now...

(a) platypus/doctemplate.py: multibuild returns the number of passes,
rather than None.

(a) tests/test_platypus_toc.py now has a test demonstrating
'preloading' the table of contents, and asserting that it cuts the
number of passes from 3 to 2 for a document with a TOC longer than one

If you 'preload' the TOC wth the correct section headings, you can get
down from 3 to 2 passes.
1 pass is not easy. I don't know think it can be done with this
TableOfContents widget. It
would need lazy drawing of forms. Here's how to 'preload' it...

toc = tableofcontents.TableOfContents()
toc.levelStyles = [tocLevelStyle] #need at least one style
tocEntries = []
for i in range(chapters):
#add tuple of (level, text, pageNum=0, key=None)
tocEntries.append((0, 'This is chapter %d' % i, 0, None))

Leszek, the time will definitely be spent inside multibuild, because
that's the outer loop!

Best Regards,

Andy Robinson
CEO/Chief Architect
ReportLab Europe Ltd.
Media House, 3 Palmerston Road, Wimbledon, London SW19 1PG, UK
Tel +44-20-8545-1570

More information about the reportlab-users mailing list