Split a PDF and Extract Pages in C#

IronPDF makes the process of editing your PDF document layouts through splitting and extracting pages a breeze. With IronPDF, you can extract singular or ranges of pages into new PdfDocument objects, which can then be saved, or further edited. This is all done thanks to the PdfDocument.CopyPage method.

Steps to Split PDF Files in C#

  • var renderer = new ChromePdfRenderer();
  • var pdf = renderer.RenderHtmlAsPdf(html);
  • var page1doc = pdf.CopyPage(0);
  • var page23doc = pdf.CopyPages(1, 2);
  • page23doc.SaveAs("Split2.pdf");

Before we get into the core process behind splitting PDF files, we have first created the HTML string which will be used to make the example PDF. The ChromePdfRenderer class is then used to convert the HTML string into a PDF document. The RenderHtmlAsPdf method performs the conversion, and the resulting PDF is stored in the PdfDocument object.

Now, we can start splitting the PDF. First, we use the CopyPage(0) method to copy the first page of the PDF, storing it in the page1doc variable. This simple line of code is all it takes to extract to specified page from the PDF. Then, using the SaveAs method, we save the page we extracted as a new, separate PDF file.

For extracting page ranges, the CopyPages method is used to extract the pages within the specified page range from the original PDF. (Remember that pages are zero-indexed, so 1 and 2 refer to the second and third pages). The resulting extracted pages are stored in the page23doc variable. Now, you can go on to further manipulate these extracted pages, or utilize the SaveAs method to save the extracted pages as a new PDF document.

Click here to view the How-to Guide, including examples, sample code, and files >