PDF.co makes it easy for you to merge PDFs and other file formats. You can merge PDF files exclusively or merge PDF, DOC, Images, XLS, and ZIP files into a single PDF. Read on to learn how to merge files in Python.

Merge PDF Files

  1. Add Files to Folder
  2. Install Requests Module
  3. Add API Key
  4. Reference Source Files and Output File
  5. Run Program
  6. PDF Merger Demo
  7. PDF Merger Video Guide

In this demonstration, we will merge 2 PDF files stored in our local machine using the /v1/pdf/merge endpoint. This endpoint is designed to merge PDF files only. If you’d like to merge PDFs and non-PDF files, please check out this demo.

Below is a GIF of the two sample PDF files and the merged PDF output.

PDF Merger Web API Source And Output PDF Files
PDF Merger Web API Source and Output PDF Files

Step 1: Add Files to Folder

First, let’s add our sample PDFs to our Python program folder. To follow along, you can download our sample files and Python code here.

Step 2: Install Requests Module

Next, if you haven’t yet, kindly install the requests module. You can do it by running this python -m pip install requests in your command line.

Step 3: Add API Key

Then, open the Python sample code and go to line 6. Add your PDF.co API Key inside the double-quotes. You can get your API Key in your dashboard here.

PDF.co API Key

Step 4: Reference Source Files and Output File

From lines 12 to 16, add your source PDF files and your desired output PDF file name.

Source Files And Output File

Step 5: Run Program

You can now run your Python program, and you should see the output PDF in your folder.

Merged PDF Output In Local Folder

Step 6: PDF Merger Demo

Here’s the PDF Merger Web API in action.

PDF.co PDF Merger Web API Demo In Python
PDF.co PDF Merger Web API Demo in Python

When you’re working with large files, we highly recommend that you use the async mode. You can find the Python sample code async version here.

Merge PDF, DOC, Images, XLS, and ZIP Files

  1. Move Files to Folder
  2. Install Requests Module
  3. Enter API Key
  4. Add Source Files and Output File
  5. Run Program
  6. PDF Merger Demo
  7. PDF Merger Video Guide

In this demonstration, we will merge a DOC and a PDF file. We will use the /v1/pdf/merge2 endpoint which supports file formats such as PDF, DOC, XLS, PNG, Zip, and more. If you only want to merge PDF files, please check out this demo.

You can view the source files and the merged output in the image below.

PDF.co Merge2 Web API Source Files And PDF Output
PDF.co Merge2 Web API Source Files And PDF Output

Step 1: Move Files to Folder

To get started, add the sample DOC and PDF to the Python program folder. You can download the sample files and Python code here.

Step 2: Install Requests Module

We will use the requests module in this program. If you haven’t yet, kindly install the requests module by running this python -m pip install requests in the command line.

Step 3: Enter API Key

Now, open the Python sample code and go to line 11. Add your PDF.co API Key inside the double-quotes. You can get your API Key in your dashboard here.

PDF.co API Key

Step 4: Add Source Files and Output File

From lines 17 to 21, add the source files and your desired output PDF file name.

PDF.co Merge2 Source Files And Output File Name

Step 5: Run Program

Run your Python program and you should see the output PDF in your folder.

PDF.co Merge2 Web API Result In Local Folder

Step 6: PDF Merger Demo

Here’s the PDF Merger Web API for any documents in action.

PDF.co Merge2 Web API Demo
PDF.co Merge Web API Demo

In this tutorial, you learned how to merge PDF files. You learned how to merge PDF files and other file formats. You also learned how to use the different PDF Merger Web APIs and what they are designed to do.

Video Guide