Welcome folks today in this blog post we will be adding the pagination
inside the footer
in pdf document using python & the reportlab
library. All the full source code of the application is shown below.
Get Started
In order to get started you need to install the library using the pip
command as shown below
pip install reportlab
After this you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from reportlab.pdfgen import canvas #---------------------------------------------------------------------- def createMultiPage(): """ Create a multi-page document """ c = canvas.Canvas("canvas_page_num.pdf") for i in range(5): page_num = c.getPageNumber() text = "This is page %s" % page_num c.drawString(100, 50, text) c.showPage() c.save() #---------------------------------------------------------------------- if __name__ == "__main__": createMultiPage() |
As you can see we are importing the reportlab
library and then we are using the for
loop to insert the page
numbers inside the footer section. And for this we are using the drawString()
method and inside it we are providing the x
and y
coordinates and then we are saving the pdf document with the custom filename.