Copying Pages between PDF Files
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()

# Create our main document
pdfdoc_a = renderer.RenderHtmlAsPdf(html_a)

# Create and select a page to copy
pdfdoc_b = renderer.RenderHtmlAsPdf(html_b)
page_to_insert = pdfdoc_b.CopyPage(1)

# 3 ways to insert:
pdfdoc_a.AppendPdf(page_to_insert)  # at the end
# or
pdfdoc_a.PrependPdf(page_to_insert)  # at the start
# or
pdfdoc_a.InsertPdf(page_to_insert, 1)  # in the middle

pdfdoc_a.SaveAs("CopiedPages.pdf")
pip install ironpdf
Copying Pages between PDF Files

Copying Pages between PDF Files

IronPDF for Python can copy pages from one PDF document and insert them into another at any position - at the end, the beginning, or a specific page index within the target document.

Getting Started

Create or load two PdfDocument objects. Use CopyPage to extract a specific page from the source document, then insert it into the target document using one of the three insertion methods.

Understanding the Code

  • CopyPage(index): Extracts a single page from a PdfDocument by its zero-based index. Returns a new single-page PdfDocument.
  • AppendPdf(page_to_insert): Adds the page to the end of the target document.
  • PrependPdf(page_to_insert): Adds the page to the beginning of the target document, before all existing pages.
  • InsertPdf(page_to_insert, index): Inserts the page at the specified zero-based position within the target document. In the example, index 1 inserts the page after the first page.

Inserting Multiple Pages

To copy and insert multiple pages at once, use CopyPages(start, end) instead of CopyPage, then insert the resulting multi-page document using the same AppendPdf, PrependPdf, or InsertPdf methods.

Learn to merge and edit PDF pages with IronPDF for Python!

Ready to Get Started?

Version:2026.11just released