How to Merge PDF Files into One Using Python – No Acrobat Needed


Merging multiple PDF files into one can be a real time-saver, especially when dealing with reports, scanned documents, or project files. While Adobe Acrobat is a common tool for this task, it's not the only way—and certainly not the most efficient for developers. In this guide, you'll learn how to merge PDF files into one using Python, all without relying on Acrobat. Whether you're combining two files or dozens, this quick Python solution helps you automate the process with just a few lines of code.
How to Merge PDF Files into One File with a Simple Python Script
Merging two or more PDF files into a single document can save you significant time and effort. In this tutorial, I’ll show you how to merge PDF files into one file with a simple Python script using free Spire.PDF for Python, a lightweight yet powerful library. With just three straightforward steps, you can combine multiple PDFs into one clean, organized file—no manual copy-pasting or expensive software required.
Steps to combine PDF files into one file without Acrobat:
Create a list to store PDF files.
Merge PDF files into one file using the Document.MergeFiles() method.
Save the Merged PDF as a new PDF through the PdfDocumentBase.SaveToFile() method.
The following code example demonstrates how to merge various PDF files into one without using Adobe Acrobat:
from spire.pdf.common import *
from spire.pdf import *
# Create a list of the PDF file paths
inputFile1 = "/test.pdf"
inputFile2 = "/Booklet.pdf"
inputFile3 = "/sample.pdf"
files = [inputFile1, inputFile2, inputFile3]
# Merge the PDF documents
pdf = PdfDocument.MergeFiles(files)
# Save the result document
pdf.Save("/MergePDFs.pdf", FileFormat.PDF)
pdf.Close()
How to Merge PDF Files in Python Using Page Cloning
Besides direct merging, free Spire.PDF for Python also allows you to combine PDF files by cloning pages from existing documents and combining them into a new file. This method gives you more flexibility—perfect for when you want to preserve specific page orders or selectively merge content. The process is beginner-friendly, with simple code and clear steps that make it easy to follow even if you're new to Python scripting.
Steps to merge PDF files into one by copying pages:
Create a list and import sample PDF files.
Create a PdfDocument instance.
Loop through imported PDF documents and insert each page of them to a new PDF using the PdfDocument.appendPage() method.
Save the new PDF with the PdfDocument.SaveToFile() method.
Here’s a Python example showing how to merge PDF files into a new one by cloning pages:
from spire.pdf.common import *
from spire.pdf import *
# Create a list of the PDF file paths
inputFile1 = "/test.pdf"
inputFile2 = "/Booklet.pdf"
inputFile3 = "/sample.pdf"
files = [inputFile1, inputFile2, inputFile3]
# Load each PDF file as a PdfDocument object and add them to a list
pdfs = []
for file in files:
pdfs.append(PdfDocument(file))
# Create an object of PdfDocument class
newPdf = PdfDocument()
# Insert the pages of the loaded PDF documents into the new PDF document
for pdf in pdfs:
newPdf.AppendPage(pdf)
# Save the new PDF document
newPdf.SaveToFile("/ClonePage.pdf")
How to Quickly Merge Selected Pages into One PDF with Python
Merging entire PDF files is the fastest way to combine documents, but it often lacks the flexibility needed for more precise tasks. Sometimes, you only want to keep specific pages from each file. Fortunately, with Python, you can easily customize which pages to merge from multiple PDFs. In this section, you’ll learn how to merge selected pages into one PDF file using Python, giving you full control over the content of the final document.
Steps to combine selected pages into a PDF:
Create a list of the PDF file paths and load sample PDF files.
Create an instance of PdfDocument class.
Insert the desired pages into the new PDF document using the PdfDocument.InsertPage() and PdfDocument.InsertPageRange() methods.
Save the new PDF through the PdfDocument.SaveToFile() method.
The following code demonstrates how to merge the 1st page of the first PDF, the 2nd page of the second PDF, and the first two pages of the third PDF into a new document:
from spire.pdf.common import *
from spire.pdf import *
# Create a list of the PDF file paths
inputFile1 = "/test.pdf"
inputFile2 = "/Booklet.pdf"
inputFile3 = "/sample.pdf"
files = [inputFile1, inputFile2, inputFile3]
# Load each PDF file as a PdfDocument object and add them to a list
pdfs = []
for file in files:
pdfs.append(PdfDocument(file))
# Create an object of PdfDocument class
newPdf = PdfDocument()
# Insert the selected pages from the loaded PDF documents into the new document
newPdf.InsertPage(pdfs[0], 0)
newPdf.InsertPage(pdfs[1], 1)
newPdf.InsertPageRange(pdfs[2], 0, 1)
# Save the new PDF document
newPdf.SaveToFile("/SelectedPages.pdf")
The Bottom Line
Merging PDF files in Python doesn’t have to be complicated. Whether you're combining entire documents or merging only selected pages, free Spire.PDF for Python offers flexible and efficient solutions. With just a few lines of code, you can tailor your output exactly the way you need—no Acrobat required.
FAQs about Merging PDF Files
Q1: How do I combine multiple PDF into one PDF?
You can combine multiple PDF files into one using tools like Adobe Acrobat or free online services such as Smallpdf or iLovePDF.
If you prefer automation, Python offers programmatic solutions using third-party libraries like free Spire.PDF or PyPDF2. These tools allow you to merge PDF files in just a few lines of code.
Q2: How can I merge PDF files for free without Adobe?
Yes, there are several free options.
Manual method: Use free online tools like PDF24, Smallpdf, or ILovePDF. Just upload your files, rearrange pages if needed, and download the merged PDF.
Subscribe to my newsletter
Read articles from Casie Liu directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
