Merge PDF Files in Python

Import pages from multiple PDF files and export the combined content as one PDF document with Python

Merge PDF in Python

Aspose.Slides for Python via .NET lets you combine PDF files by importing their pages into a Presentation. SlideCollection.add_from_pdf converts each PDF page into a slide and appends it to the presentation.

After all source files are imported, call Presentation.save with SaveFormat.PDF to export the slides as one PDF document. Microsoft PowerPoint and Adobe Acrobat are not required.

Merge PDF files using Python

Create a presentation without its default blank slide, import the source PDF files in the required order, and export the combined slides as one PDF document.

Python code for merging PDF files

with slides.Presentation() as presentation:
    presentation.slides.remove_at(0)
    presentation.slides.add_from_pdf("document1.pdf")
    presentation.slides.add_from_pdf("document2.pdf")

    presentation.save("merged.pdf", slides.export.SaveFormat.PDF)

How to merge PDF using Aspose.Slides for Python API

These are the steps to merge PDF files in Python.

  1. Install Aspose.Slides for Python via .NET .

  2. Create an empty Presentation.

  3. Remove the default blank slide from the presentation.

  4. Pass each source PDF file to SlideCollection.add_from_pdf in the required order.

  5. Call Presentation.save with the output file path and SaveFormat.PDF.