將頁面添加到帶有C++的 PDF 檔

C++ 庫,用於使用我們的 API 將頁面添加到 PDF。

如何使用C++將頁面添加到 PDF

為了在PDF檔中插入頁面,我們將使用[Aspose.PDF for C++](https://products.aspose.com/pdf/cpp)API,這是一個功能豐富,功能強大且易於使用的文檔操作API,適用於 cpp 平臺。打開 [NuGet](https://www.nuget.org/packages/aspose.pdf) 包管理器,搜索“.PDF”並安裝。您也可以從程式包管理器主控台使用以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

通過C++將頁面插入到 PDF 中


您需要 [Aspose.PDF for C++](https://releases.aspose.com/pdf/cpp) 才能在您的環境中嘗試代碼。

  1. 使用輸入的 PDF 檔案建立一個文件 物件。

  2. 使用指定的索引調用 頁面收集 集合的插入方法。

  3. 使用「保存」 方法保存輸出的 PDF。

將新頁面插入到 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);
}