[reportlab-users] getting PDF page labels

Christian Jacobsen cljacobsen at gmail.com
Sat Nov 14 12:27:19 EST 2009

I don't think you are going to find anything useful that you can
access to draw the page numbers. You will probably have to just keep
track of the numbering in your program and generate both PageLabels
and actual printed page numbers from your own page numbering data.

What is actually stored in the PDF is just a reference for each time
the page numbering changes. Each page does not store its page number
and numbering system, this is calculated by the PDF reader when the
page is displayed. Thus there is nothing which will let you query the
logical page number (PageLabel) of a particular page directly from the


2009/11/14 Jeffrey O'Neill <jeff.oneill at openstv.org>:

> 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()

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at lists2.reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users


More information about the reportlab-users mailing list