Split PDF programmatically
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
The following C# code snippet shows you how to split PDF pages into individual PDF files.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SplitDocument()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open PDF document
using (var document1 = new Aspose.Pdf.Document(dataDir + "SplitToPages.pdf"))
{
int pageCount = 1;
// Loop through all the pages
foreach (var page in document1.Pages)
{
// Create PDF document
using (var document2 = new Aspose.Pdf.Document())
{
document2.Pages.Add(page);
// Save PDF document
document2.Save(dataDir + "Page_" + pageCount + "_out.pdf");
pageCount++;
}
}
}
}