Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Split PDF files using C++
Split PDF file using Aspose.PDF for C++ API
// Load PDF file
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\Sample 1.pdf");
// Page counter
int pageCount = 1;
// Loop through all the pages
for (auto page : pdfDocument->get_Pages())
{
// Create new document
auto newDoc = MakeObject<Document>();
// Add page to the document
newDoc->get_Pages()->Add(page);
// Save as PDF
newDoc->Save(u"OutputDirectory\\Sample_Page_" + System::Convert::ToString(pageCount) + u"_out.pdf");
pageCount++;
}
// Load PDF file
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\Sample 1.pdf");
// Create new document
auto newDoc = MakeObject<Document>();
// Page counter
int pageCount = 1;
// Loop through all the pages
for (auto page : pdfDocument->get_Pages())
{
// Get only even pages
if (pageCount % 2 == 0)
{
// Add page to the document
newDoc->get_Pages()->Add(page);
}
pageCount++;
}
// Save as PDF
newDoc->Save(u"OutputDirectory\\Sample_Even_Pages_out.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment