ZingPDF logo

Guide

How to export selected pages or split a PDF in C#

Use ExportPagesAsync(...) when you need a new PDF containing specific 1-based page numbers in a specific order. Use SplitAsync(...) when you want fixed-size chunks from the full document.

Both APIs return new Pdf instances, so save or continue editing those outputs just like any other document.

Export selected pages into a new PDF

Pass the 1-based page numbers you want, save the returned PDF, and dispose it when you are done.

using var pdf = Pdf.Load(File.OpenRead("input.pdf"));
using var selectedPages = await pdf.ExportPagesAsync([1, 3, 5]);
using var output = File.Create("selected-pages.pdf");

await selectedPages.SaveAsync(output);

The exported document keeps the order you asked for, so [5, 1, 3] produces a PDF in that same order.

Split a document into fixed-size parts

SplitAsync(pagesPerDocument) creates a list of new PDFs, each with up to the requested number of pages.

using var pdf = Pdf.Load(File.OpenRead("input.pdf"));
var parts = await pdf.SplitAsync(10);

try
{
    for (var index = 0; index < parts.Count; index++)
    {
        using var output = File.Create($"part-{index + 1}.pdf");
        await parts[index].SaveAsync(output);
    }
}
finally
{
    foreach (var part in parts)
    {
        part.Dispose();
    }
}

The last part may contain fewer pages than the others if the input page count is not an exact multiple of the split size.

Page numbers are 1-based and must be unique

ExportPagesAsync(...) uses the same 1-based page numbering as the rest of the API.

If you are selecting pages manually, validate that the numbers are within the current document page count before building the export list.

Current limitations

This is designed for page export and document splitting. If you are working with interactive forms, flatten the form first when you need a clean non-interactive output.

Need to assemble pages before you split them?

Reordering, inserting, and removing pages often comes right before export.

Read How to insert, append, and delete PDF pages in C#.

Open docs All guides