Skip to content

Split a PDF into one file per page in C#

Since 1.0View as Markdown

Turn every page of a PDF into a file of its own.

PdfDocument.Split returns one new document per page. Save each one under its own name. Inherited page attributes such as resources, media box and rotation are materialized on each page, so every file stands on its own.

recipe-split-pdf.cs
#:package PdfNetStack@1.2.0
using PdfNetStack;
PdfDocument doc = PdfDocument.Open("report.pdf");
int number = 1;
foreach (PdfDocument single in doc.Split()) // one new document per page
{
single.Save($"report-page-{number}.pdf");
number++;
}
Console.WriteLine($"Wrote {number - 1} files");
Terminal window
dotnet add package PdfNetStack

To keep groups of pages together rather than single pages, import the pages you want into a new document, as in Extract pages from a PDF.