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
Create an instance of the Merger class and pass the path to the first (base) PDF file.
Call merger.join() with the path to each additional PDF to append.
Call merger.save() with the desired output path to write the merged file.
fromgroupdocs.mergerimportMergerdefmerge_pdf_documents():# Load the first document as the merge basewithMerger("./input.pdf")asmerger:# Append the second PDF documentmerger.join("./input2.pdf")# Save the combined documentmerger.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.
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.
fromgroupdocs.mergerimportMergerfromgroupdocs.merger.domain.optionsimportPdfJoinOptionsdefmerge_pdf_with_bookmarks():# Load the first document as the merge basewithMerger("./input.pdf")asmerger:# Configure join options to preserve bookmarkspdf_join_options=PdfJoinOptions()pdf_join_options.use_bookmarks=True# Append the second PDF document with bookmark options appliedmerger.join("./input2.pdf",pdf_join_options)# Save the combined documentmerger.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.
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.