[reportlab-users] TOC with related page numbers

Jerome Alet reportlab-users@reportlab.com
Wed, 4 Sep 2002 19:36:03 +0200

On Wed, Sep 04, 2002 at 06:53:23PM +0200, Nathalie Mansouri wrote:
> I have created a pdf and included a TOC but I want to include also the 
> page numbers for each title. Is there a way to do that?

depending on how you made your TOC, you may be able to draw a 
different form for each title line in the TOC, and define each
form's content at the end.

if titles is the list of titles, titlespages is the list of titles' 
page numbers, and N is the number of entries in your TOC, just do
something like that to construct your TOC :

for i in range(N) :
        canv.drawString(x, y, "%s" % titles[i])
        canv.doForm("formname%i" % i)
and just do the following just before ending your document : 

        for i in range(N) :
            canv.beginForm("formname%i" % i)
            canv.drawString(0, 0, "Page %i" % titlespages[i])
This is completely untested but should work.            


Jerome Alet