Click or drag to resize
Pdf Library for .NET

Split Pdf Documents

SelectPdf Library for .NET splits existing PDF documents with PdfSplitManager: it extracts pages into a new document, or divides a document into several documents by page count, at its top level bookmarks or by file size.

Load the document with one of the Load overloads (an encrypted document with its user or owner password), then call the operations. Each operation returns new PdfDocument objects, which can be changed further (pages added, security set, headers stamped) and must be saved and closed by the caller. The loaded document is not modified, and each extracted document keeps its document information (title, author, subject, keywords).

Split Operations
  • ExtractPages(String) - the pages of a list such as "1,3-5,7-" (single pages, ranges, an open range up to the last page), in the order given.

  • ExtractOddPages and ExtractEvenPages - every other page, for instance to print a two-sided document on a one-sided printer.

  • Split(Int32) - documents of a fixed number of pages; the last one holds what is left.

  • SplitByBookmarks - one document per top level bookmark (a chapter), titled with the bookmark's text; the pages before the first bookmark make a document of their own.

  • SplitBySize(Int64) - documents of at most a number of bytes, each holding as many pages as fit, for instance to stay under an email attachment limit. A single page larger than the limit makes a document of its own.

Sample Code
using (PdfSplitManager splitter = new PdfSplitManager())
{
    splitter.Load("report.pdf");

    // the summary: pages 1 and 3 to 5
    PdfDocument summary = splitter.ExtractPages("1,3-5");
    summary.Save("summary.pdf");
    summary.Close();

    // one document per chapter
    PdfDocument[] chapters = splitter.SplitByBookmarks();
    for (int i = 0; i < chapters.Length; i++)
    {
        chapters[i].Save("chapter-" + (i + 1) + ".pdf");
        chapters[i].Close();
    }

    // pieces of at most 5 MB
    PdfDocument[] pieces = splitter.SplitBySize(5 * 1024 * 1024);
    for (int i = 0; i < pieces.Length; i++)
    {
        pieces[i].Save("piece-" + (i + 1) + ".pdf");
        pieces[i].Close();
    }
}
Notes
  • Bookmarks and form fields come with the pages they are on. The logical structure (tags) and a PDF/A or PDF/UA claim of the source do not: the extracted documents are plain PDF documents.

  • Merging is the opposite operation: see Pdf Merge.

See Also

Reference

PdfSplitManager
PdfDocument

Other Resources

Pdf Merge