# Split a PDF into one file per page in C#

> Split a PDF into single page files in .NET with PdfDocument.Split, each saved as a valid, optimized PDF. MIT licensed, pure C#.

Available since 1.0.

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

## Short answer

`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.

```csharp title="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");
```

```bash
dotnet add package PdfNetStack
```

## Variations

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](https://www.jadev-corp.com/recipes/extract-pdf-pages/).

## Related

- [Edit pages](https://www.jadev-corp.com/guides/edit-pages/)
- [Command line](https://www.jadev-corp.com/cli/): `pdfnetstack split in.pdf ./pages`
- API: [PdfDocument](https://www.jadev-corp.com/api/pdfnetstack/pdfdocument/)

Source: https://www.jadev-corp.com/pdfnetstack/recipes/split-pdf/
