Add Pages to PDF via C++

Insert pages to PDF document programmatically using Aspose.PDF for C++ Library

How to Add pages to PDF Using C++

In order to insert page in PDF file, we’ll use Aspose.PDF for C++ API which is a feature-rich, powerful and easy to use document manipulation API for cpp platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

Insert Page to PDF via C++


You need Aspose.PDF for C++ to try the code in your environment.

  1. Create a Document object with the input PDF file.

  2. Call the PageCollection collection’s Insert method with specified index.

  3. Save the output PDF using the Save method.

Insert New Page to PDF


    void InsertEmptyPageAtDesiredLocation() {
    // Open document
    String _dataDir("C:\\Samples\\");

    // String for input file name
    String inputFileName("InsertEmptyPage.pdf");

    String outputFileName("InsertEmptyPage_out.pdf");

    auto document = MakeObject<Document>(_dataDir + inputFileName);

    // Insert a empty page in a PDF
    document->get_Pages()->Insert(2);

    // Save output file
    document->Save(_dataDir + outputFileName);
}