Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active March 18, 2021 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/93276a7077c995408e36ef974aa241d5 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/93276a7077c995408e36ef974aa241d5 to your computer and use it in GitHub Desktop.
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