[reportlab-users] getting PDF page labels

Jeffrey O'Neill jeff.oneill at openstv.org
Sat Nov 14 11:51:08 EST 2009


A couple of weeks ago, Christian Jacobsen posted a great example of
how to set the page labels so that a document could have pages, e.g.,
i, ii, ... vi, 1, 2, ..., 100. I'm pasting that example below for
reference.

Is there a way to access the pdf page labels so that I can use them in
drawing the page numbers on the page and including them in a table of
contents?

Jeff


-------------8<-------------------8<-------------------8<------------------
from reportlab.pdfgen import canvas
from reportlab.lib.units import cm
c = canvas.Canvas("page_numbering.pdf")
c.addPageLabel(c.getPageNumber()-1, 'ROMAN_LOWER')
for num in ['i', 'ii', 'iii', 'iv', 'v']:
c.drawString(3*cm, 3*cm, num)
c.showPage()
c.addPageLabel(c.getPageNumber()-1, 'ARABIC')
for num in range(1,5):
c.drawString(3*cm, 3*cm, str(num))
c.showPage()
c.addPageLabel(c.getPageNumber()-1, 'ARABIC', 10)
for num in range(10,15):
c.drawString(3*cm, 3*cm, str(num))
c.showPage()
c.addPageLabel(c.getPageNumber()-1, 'ARABIC', prefix='A.')
for num in range(1,5):
c.drawString(3*cm, 3*cm, 'A.' + str(num))
c.showPage()
c.save()


More information about the reportlab-users mailing list