PDF Merger via Python

Merge documents. Use Aspose.PDF for Python via C++ to modify PDF files programmatically

How to Merge PDF files Using Python via C++

In order to merge PDF files, we’ll use Aspose.PDF API which is a feature-rich, powerful, and easy-to-use document manipulation API for python-cpp platform. Our Python via C++ Library can convert a document from any supported download format to any supported save format. Aspose.PDF for Python via C++ library provides fairly universal solutions that will help you solve the tasks of converting documents. Aspose.PDF supports the largest number of popular document formats, both for loading and saving. Draw your attention that the current section describes only popular conversions. The current page provides information about converting the format to format. However, there are many combinations for converting your files. For a complete list of supported formats, see the section Supported File Formats. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Merge PDF files via Python


You need Aspose.PDF library to try the code in your environment.

  1. Open first document.
  2. Open second document.
  3. Add pages of second document to the first.
  4. Save concatenated output file

Python - example code to merge PDF files


    dataDir = os.path.join(os.getcwd(), "samples")
    input_file= os.path.join(dataDir , "sample0.pdf")
    output_file = os.path.join(dataDir , "results", "concatenated-files.pdf")

    # Open first document
    document1 = apw.Document(inputFile)
    document2 = apw.Document(inputFile)

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

    # Save concatenated output file
    document1.save(output_file)