Split PDF programmatically
Contents
[
Hide
]
Live Example
Aspose.PDF Splitter is an online free web application that allows you to investigate how presentation splitting functionality works.
This topic shows how to split PDF pages into individual PDF files in your .NET applications. To split PDF pages into single page PDF files using C#, the following steps can be followed:
- Loop through the pages of PDF document through the Document object’s PageCollection collection
- For each iteration, create a new Document object and add the individual Page object into the empty document
- Save the new PDF using Save method
The following code snippet also work with Aspose.PDF.Drawing library.
Split PDF into multiple files or separate pdfs in C#
The following C# code snippet shows you how to split PDF pages into individual PDF files.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open document
Document pdfDocument = new Document(dataDir + "SplitToPages.pdf");
int pageCount = 1;
// Loop through all the pages
foreach (Page pdfPage in pdfDocument.Pages)
{
Document newDocument = new Document();
newDocument.Pages.Add(pdfPage);
newDocument.Save(dataDir + "page_" + pageCount + "_out" + ".pdf");
pageCount++;
}