How to merge multiple PDF files using Python?

python @

Use case : If you have multiple files for example chapter wise question papers etc. and you need to have all in a single file then you need to merge all the files. If there are some confidential data then it is not safe to use online tool. This can be accomplished by the following code.

Library used :  PyPDF2 Official Page

import os
from PyPDF2 import PdfFileMerger
pdf_lst   = os.listdir("D:\freshers\pdf_files")
# The above will get the list of pdf from the path. 
#You can give the pdfs as list if you want only specific files.
merger = PdfFileMerger()
for pdf in pdf_lst:

pdf_lst => Will get all the files from that path , instead you can create a list with the files that you need and run. Files that you mentioned only will be merged.

Useful links

  1. Python articles
  2. Spark Interview Questions
  3. Spark Examples
  4. PySpark Blogs
  5. Bigdata Blogs
  6. Official Page
Author: user

Leave a Reply