Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 ReportLab Library to Add Pagination at Footer inside PDF Document in Command Line

Posted on January 17, 2023

 

 

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

 

 

Python
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.

 

 

 

Recent Posts

  • Android Java Project to Capture Image From Camera & Save it in SharedPreferences & Display it in Grid Gallery
  • Android Java Project to Store,Read & Delete Data Using SharedPreferences Example
  • Android Java Project to Download Multiple Images From URL With Progressbar & Save it inside Gallery
  • Android Java Project to Capture Image From Camera & Save it inside Gallery
  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme