Split Documents

This demo uses the DevExpress PDF Document API (PdfDocumentProcessor) to split a document into logical parts.

You can split the predefined sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu. In the Split Settings panel, specify the document pages you want to extract.

Use the Split Document button to split the PDF file and download the result.

Select a Document
Sample_Main.pdf



using DevExpress.Pdf;

IReadOnlyList<Stream> SplitDocuments(Stream documentStream, IEnumerable<int> pageRange) {
    using var processor = new PdfDocumentProcessor();
    processor.LoadDocument(documentStream);

    if(!pageRange.Any())
        pageRange = Enumerable.Range(0, processor.Document.Pages.Count);

    var result = new List<Stream>();
    foreach(var index in pageRange) {
        if(index < 0 || index >= processor.Document.Pages.Count)
            continue;

        using var pageProcessor = new PdfDocumentProcessor();
        pageProcessor.CreateEmptyDocument();
        pageProcessor.Document.Pages.Add(processor.Document.Pages[index]);

        var outputStream = new MemoryStream();

        pageProcessor.SaveDocument(outputStream);

        outputStream.Position = 0;
        result.Add(outputStream);
    }

    return result;
}