This demo uses the New DevExpress PDF Document API (PdfDocument) to split a PDF document by pages.
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
Split Settings
using DevExpress.Docs.Pdf;
IReadOnlyList<Stream> SplitDocuments(Stream documentStream, IEnumerable<int> pageRange) {
using var source = new PdfDocument(documentStream);
if(!pageRange.Any())
pageRange = Enumerable.Range(0, source.Pages.Count);
var result = new List<Stream>();
foreach(var index in pageRange) {
if(index < 0 || index >= source.Pages.Count)
continue;
using var pageDoc = new PdfDocument();
pageDoc.Pages.Add(source.Pages[index].Clone());
var outputStream = new MemoryStream();
pageDoc.Save(outputStream);
outputStream.Position = 0;
result.Add(outputStream);
}
return result;
}