Split a PDF and Extract Pages
from ironpdf import *

html = """<p> Hello Iron </p>
          <p> This is 1st Page </p>
          <div style='page-break-after: always;'></div>
          <p> This is 2nd Page</p>
          <div style='page-break-after: always;'></div>
          <p> This is 3rd Page</p>"""

renderer = ChromePdfRenderer()
pdf = renderer.RenderHtmlAsPdf(html)

# take the first page
page1doc = pdf.CopyPage(0)
page1doc.SaveAs("Split1.pdf")

# take the pages 2 & 3
page23doc = pdf.CopyPages(1, 2)
page23doc.SaveAs("Split2.pdf")
pip install ironpdf
Split a PDF and Extract Pages

Split a PDF and Extract Pages

IronPDF for Python can split a PDF document into multiple separate files by copying specific pages or page ranges from the original document.

Getting Started

Create or load a multi-page PdfDocument, then use CopyPage to extract a single page or CopyPages to extract a range of pages. Each call returns a new PdfDocument containing only the specified pages, which can then be saved independently.

Understanding the Code

  • RenderHtmlAsPdf(html): Renders a multi-page HTML document (using page-break-after: always to create page breaks) into a PdfDocument.
  • CopyPage(index): Returns a new single-page PdfDocument containing the page at the given zero-based index. In the example, index 0 extracts the first page.
  • CopyPages(start, end): Returns a new PdfDocument containing the pages from start to end (inclusive, zero-based). In the example, indexes 1 and 2 extract pages 2 and 3.
  • SaveAs(path): Saves each resulting document to its own file.

Zero-Based Indexing

IronPDF uses zero-based page indexing throughout its API. Page 1 of a document is at index 0, page 2 is at index 1, and so on.

Learn to merge and split PDFs with IronPDF for Python!

Ready to Get Started?

Version:2026.11just released