Move Pages to PDF via C++

Move Pages in PDF document. Use Aspose.PDF for C++ to modify PDF files programmatically

How to Move pages to PDF Using C++

In order to move 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

Move 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. Get Page from the the PageCollection collection’s.
  3. Save the output PDF using the Save method.
  4. Add page to the destination document. Save output file.
  5. Delete page in source document.
  6. Save the source PDF using the Save method.

Moving a Page from one PDF Document to Another


void MovePage()
{
    // Open document
    String _dataDir("C:\\Samples\\");
    String srcFileName("<enter file name>");
    String dstFileName("<enter file name>");

    auto srcDocument = MakeObject<Document>(_dataDir + srcFileName);
    auto dstDocument = MakeObject<Document>();

    auto page = srcDocument->get_Pages()->idx_get(2);
    dstDocument->get_Pages()->Add(page);
    // Save output file
    dstDocument->Save(srcFileName);
    srcDocument->get_Pages()->Delete(2);
    srcDocument->Save(dstFileName);
}