为了在 PDF 文件中添加书签,我们将使用 Aspose.PDF for C++ API,这是一款适用于 cpp 平台的功能丰富、功能强大且易于使用的文档操作 API。打开 NuGet 软件包管理器,搜索 aspose.pdf 然后安装。您也可以在软件包管理器控制台中使用以下命令。
PM > Install-Package Aspose.PDF.Cpp
通过 C++ 使用书签的步骤
你需要 Aspose.PDF for C++ 才能在你的环境中试用代码。
1.使用文档对象打开 PDF 文档。
1.创建书签并定义其属性。
1.将 OutlineItemCollection 集合添加到 OutlineC
1.再次保存该文件
<% bookmarks.code-block.text %>
在 PDF 文档中添加书签-C++。
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");