How to Merge PDF using Python

Merge or combine multiple PDF into single PDF in Python

Combining PDF files is a very popular query among users This can be useful when you have several PDF files that you want to share or store together as one document.

Merging PDF files can help you organize your documents, make room for storage on your PC, and share several PDF files with others by combining them into one document.

Merging PDF in Python via .NET is not straightforward task without using 3rd party library. This article shows how to merge multiple PDF files into a single PDF document using Aspose.PDF for Python via .NET.

Merge PDF Files using Python and DOM

To concatenate two PDF files:

  1. Create two Document objects, each containing one of the input PDF files.
  2. Then call the PageCollection collection’s add() method for the Document object you want to add the other PDF file to.
  3. Pass the PageCollection collection of the second Document object to the first PageCollection collection’s add() method.
  4. Finally, save the output PDF file using the save() method.

The following code snippet shows how to concatenate PDF files.


    import aspose.pdf as ap

    # Open first document
    document1 = ap.Document(input_pdf_1)
    # Open second document
    document2 = ap.Document(input_pdf_2)

    # Add pages of second document to the first
    document1.pages.add(document2.pages)

    # Save concatenated output file
    document1.save(output_pdf)

Live Example

Aspose.PDF Merger is an online free web application that allows you to investigate how presentation merging functionality works.

Aspose.PDF Merger