Last active
November 4, 2020 01:45
-
-
Save aspose-com-gists/4a65283c94c4ab99a1cd65ddf247df2c to your computer and use it in GitHub Desktop.
Split PDF Files in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
Document pdfDocument = new Document("merged.pdf"); | |
// Select even pages only | |
Aspose.Pdf.Page[] evenPages = pdfDocument.Pages.Where(x => x.Number % 2 == 0).ToArray(); | |
// Select odd pages only | |
Aspose.Pdf.Page[] oddPages = pdfDocument.Pages.Where(x => x.Number % 2 != 0).ToArray(); | |
// Save even pages as PDF | |
Document newDocument = new Document(); | |
newDocument.Pages.Add(evenPages); | |
newDocument.Save("split_even_Pages.pdf"); | |
// Save odd pages as PDF | |
newDocument = new Document(); | |
newDocument.Pages.Add(oddPages); | |
newDocument.Save("split_odd_Pages.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
Document pdfDocument = new Document("merged.pdf"); | |
// For page counter | |
int pageCount = 1; | |
// Loop through all the pages | |
foreach (Aspose.Pdf.Page pdfPage in pdfDocument.Pages) | |
{ | |
// Create a new document | |
Document newDocument = new Document(); | |
// Add page to the document | |
newDocument.Pages.Add(pdfPage); | |
// Save as PDF | |
newDocument.Save("page_" + pageCount + "_out" + ".pdf"); | |
pageCount++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment