Joining Two or More PDFs
from ironpdf import *

html_a = """<p> [PDF_A] </p>
            <p> [PDF_A] 1st Page </p>
            <div style='page-break-after: always;'></div>
            <p> [PDF_A] 2nd Page</p>"""

html_b = """<p> [PDF_B] </p>
            <p> [PDF_B] 1st Page </p>
            <div style='page-break-after: always;'></div>
            <p> [PDF_B] 2nd Page</p>"""

renderer = ChromePdfRenderer()

pdfdoc_a = renderer.RenderHtmlAsPdf(html_a)
pdfdoc_b = renderer.RenderHtmlAsPdf(html_b)
merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b)

merged.SaveAs("Merged.pdf")
pip install ironpdf
Joining Two or More PDFs

Joining Two or More PDFs

IronPDF for Python can combine multiple PDF documents into a single file using the PdfDocument.Merge method, making it straightforward to assemble multi-part documents from separate sources.

Getting Started

Create or load two or more PdfDocument objects, then pass them to PdfDocument.Merge. The method returns a new PdfDocument containing all pages from the input documents in the order they were provided.

Understanding the Code

  • ChromePdfRenderer: Used here to render two HTML strings into separate PdfDocument objects. You can also load existing PDFs with PdfDocument.FromFile.
  • RenderHtmlAsPdf(html): Converts an HTML string into a PdfDocument. Each rendered document becomes one section of the final merged PDF.
  • PdfDocument.Merge(pdfdoc_a, pdfdoc_b): Combines two PdfDocument objects into a single document. The pages from pdfdoc_a appear first, followed by the pages from pdfdoc_b.
  • SaveAs("Merged.pdf"): Saves the merged document to the specified file path.

Merging More Than Two Documents

To merge more than two documents at once, pass a list of PdfDocument objects to PdfDocument.Merge:

merged = PdfDocument.Merge([doc_a, doc_b, doc_c])
Python
Learn to merge and split PDFs with IronPDF for Python!

Ready to Get Started?

Version:2026.11just released