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 (usingpage-break-after: alwaysto create page breaks) into aPdfDocument.CopyPage(index): Returns a new single-pagePdfDocumentcontaining the page at the given zero-based index. In the example, index0extracts the first page.CopyPages(start, end): Returns a newPdfDocumentcontaining the pages fromstarttoend(inclusive, zero-based). In the example, indexes1and2extract 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.






