通過C++處理 PDF 文件中的書籤

如何使用 C++以程式設計方式操作 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++使用書籤的步驟


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

  1. 使用文件對象打開 PDF 文件。
  2. 建立書籤並定義其屬性。
  3. 將大綱專案集合添加到大綱集合。
  4. 再次儲存檔

<% bookmarks.code-block.text %>

將書籤加入到 PDF 文件 - C++。

<% bookmarks.code-block.subtitle %>

    auto pdfOutline = MakeObject<OutlineItemCollection>(pdfDocument->get_Outlines());
    pdfOutline->set_Title(u"Test Outline");
    pdfOutline->set_Italic(true);
    pdfOutline->set_Bold(true);

    // Set the destination page number
    pdfOutline->set_Action(MakeObject<Aspose::Pdf::Annotations::GoToAction>(pdfDocument->get_Pages()->idx_get(2)));

    // Add a bookmark in the document's outline collection.
    pdfDocument->get_Outlines()->Add(pdfOutline);

    // Save the update document
    pdfDocument->Save(_dataDir + u"AddBookmark_out.pdf");