Merge PDF

GroupDocs.Merger for Python via .NET lets you combine multiple PDF documents into a single file programmatically. All text, images, tables, graphs, forms, and other content are preserved exactly as in the originals — no third-party software or manual work required.

Steps to merge PDF files

  1. Create an instance of the Merger class and pass the path to the first (base) PDF file.
  2. Call merger.join() with the path to each additional PDF to append.
  3. Call merger.save() with the desired output path to write the merged file.
from groupdocs.merger import Merger

def merge_pdf_documents():
    # Load the first document as the merge base
    with Merger("./input.pdf") as merger:
        # Append the second PDF document
        merger.join("./input2.pdf")
        # Save the combined document
        merger.save("./output.pdf")

if __name__ == "__main__":
    merge_pdf_documents()

input.pdf is a sample file used in this example. Click here to download it.

input2.pdf is a sample file used in this example. Click here to download it.

Binary file (PDF, 252 KB)

Download full output

Explanation

  • Load base document: Merger("./input.pdf") opens the first PDF as the merge base inside a context manager, ensuring resources are released automatically.
  • Append second document: merger.join("./input2.pdf") appends the content of the second PDF. Call join again for each additional file.
  • Save result: merger.save("./output.pdf") writes the merged PDF to disk.

Merge PDF with bookmark options

Use PdfJoinOptions to control how PDF content is joined. For example, setting use_bookmarks=True preserves the source document bookmarks in the merged output.

from groupdocs.merger import Merger
from groupdocs.merger.domain.options import PdfJoinOptions

def merge_pdf_with_bookmarks():
    # Load the first document as the merge base
    with Merger("./input.pdf") as merger:
        # Configure join options to preserve bookmarks
        pdf_join_options = PdfJoinOptions()
        pdf_join_options.use_bookmarks = True
        # Append the second PDF document with bookmark options applied
        merger.join("./input2.pdf", pdf_join_options)
        # Save the combined document
        merger.save("./output.pdf")

if __name__ == "__main__":
    merge_pdf_with_bookmarks()

input.pdf is a sample file used in this example. Click here to download it.

input2.pdf is a sample file used in this example. Click here to download it.

Binary file (PDF, 252 KB)

Download full output

Explanation

  • PdfJoinOptions: Provides PDF-specific join settings.
  • use_bookmarks = True: Instructs the merger to retain the document outline (bookmarks) from each source PDF so readers can navigate the merged result.

About PDF File Format

Portable Document Format (PDF) is a type of document created by Adobe back in the 1990s. The purpose of this file format was to introduce a standard for representation of documents and other reference material in a format that is independent of application software, hardware, and Operating System. PDF files can be opened in Adobe Acrobat Reader/Writer as well as in most modern browsers like Chrome, Safari, and Firefox via extensions/plug-ins.

Merge PDF Live Demo

GroupDocs.Merger for Python via .NET provides an online PDF Merger App, which allows you to try it for free and check its quality and accuracy.

“Merge PDF”

API reference

See also