[reportlab-users] Page n of m?

Paul.Keating at nibc.com Paul.Keating at nibc.com
Mon Aug 18 05:48:58 EDT 2008


Harald,

Thanks for the help. I'd never have worked that out for myself.

One other question: is it possible to retrieve and store the cursor
position of the page number, so that when I do the drawString() later, I
have the exact coordinates and don't need to recompute them? My problem is
the position of the page number isn't fixed, it depends on what is above it
in the frame.

Regards

P



> Yes, it is possible.

>

> Usually the solution is:

>

> 1) add "Page <actual Page> of" to the footer of your Page

> canv.drawRightString(10*cm, 0.75*cm, u"Page %s of % (doc.page,))

>

> 2) add a PDF-Form to the place right of the "of"

> canv.doForm("pageCount")

>

> 3) render the PDF

> 4) after the rendering, fill the Number of Pages into PDF-Form which

> gets drawn after the "of"

> def _endBuild(self):

> self.canv.beginForm("pageCount")

> self.canv.setFont(fontnormal,7)

> self.canv.drawString(12*cm,0.75*cm u"%s" % (self.canv.

> getPageNumber(),))

> self.canv.endForm()

> BaseDocTemplate._endBuild(self)







More information about the reportlab-users mailing list