Split PDF programmatically

Contents
[ ]

Live Example

Aspose.PDF Splitter is an online free web application that allows you to investigate how presentation splitting functionality works.

Aspose Split PDF

This topic shows how to split PDF pages into individual PDF files in your C++ applications. To split PDF pages into single page PDF files using C++, the following steps can be followed:

  1. Loop through the pages of PDF document through the Document object’s PageCollection collection
  2. For each iteration, create a new Document object and copy the individual Page object into the empty document
  3. Save the new PDF using Save method

The following C++ code snippet shows you how to split PDF pages into individual PDF files.

void SplittingDocuments() {
    // String for path name
    String _dataDir("C:\\Samples\\");

    // String for input file name
    String documentFileName("sample.pdf");
    
    // Open document
    auto document = MakeObject<Document>(_dataDir + documentFileName);

    int pageCount = 1;

    // Loop through all the pages
    for(auto page : document->get_Pages())
    {
        auto newDocument = MakeObject<Document>(_dataDir + documentFileName);
        newDocument->get_Pages()->CopyPage(page);
        newDocument->Save(_dataDir + u"page_" + pageCount + u"_out.pdf");
        pageCount++;
    }
}