How to merge n pdfs to one pdf using python.

Md Danish
2 min readJun 26, 2021

Hi, I am writing this article for the first time so ignore if there is anything wrong and let me know in the comment section to improve.

pdf image from pixabay.com

Why pdf merging is required?

A lot of times when someone registers online and you have a number of documents to upload but only one document is allowed to upload. Then there is only one option to upload all the documents is to merge them into a single pdf and upload it. There can be a number of scenarios where pdf merging is required.

What are the requirements to merge pdf?

If you are on Linux/windows then you need to install python and a python library called PyPDF2 and you are good to go!

To install python go to the link download and install it. Use pip python manager to install PyPDF2.

pip install pypdf2

Now you are ready to merge the pdf.

Copy the code and save it as merge-n-pdfs-into-single-pdf.py. Open cmd and go to the location where this file is present. Write a usage command to run the code and merge the files into a single pdf file.

python ./merge-n-pdfs-into-single-pdf.py 
--ifiles file1.pdf file2.pdf --ofile finalFile.pdf

Here file1.pdf and file2.pdf are merged into a single pdf called finalFile.pdf.

Hope you liked it!

--

--