使用 C++ 管理 PDF 中的註釋

管理 PDF 文件中的註釋。在 C++ 中使用 Aspose.PDF 以編程方式修改 PDF 文件

如何使用 C++ 程式庫管理註釋

為了在 PDF 文件中添加文本註釋,我們將使用 [Aspose.PDF for C++](https://products.aspose.com/pdf/cpp)API,該 API 是 cpp 平台的功能豐富,功能強大且易於使用的文檔操作 API。打開 [NuGet](https://www.nuget.org/packages/aspose.pdf)軟件包管理器,搜索 ** Aspose.pdf** 並安裝。您也可以使用套件管理員主控台中的下列命令。

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

通過 C++ 在 PDF 文件中創建註釋


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

1.在文件類別的執行個體中載入 PDF。 1.建立您要新增至 PDF 的註解。 1.將註釋加入到「頁面」物件的「註釋」集合中。 1.儲存 PDF 檔案。

PDF 文字註解-C++

Example: C++


auto document = MakeObject<Document>(_dataDir + u"sample.pdf");

auto page = document->get_Pages()->idx_get(1);
auto rect = MakeObject<Rectangle>(200, 750, 400, 790);
auto textAnnotation = 
    MakeObject<Aspose::Pdf::Annotations::TextAnnotation>(page, rect);

textAnnotation->set_Title(u"Aspose User");
textAnnotation->set_Subject(u"Sample Subject");
textAnnotation->set_State(Aspose::Pdf::Annotations::AnnotationState::Accepted);
textAnnotation->set_Contents(u"Sample contents for the annotation");
textAnnotation->set_Open(true);
textAnnotation->set_Icon(Aspose::Pdf::Annotations::TextIcon::Circle);

auto border = MakeObject<Aspose::Pdf::Annotations::Border>(textAnnotation);
border->set_Width(5);
border->set_Dash(MakeObject<Aspose::Pdf::Annotations::Dash>(1, 1));
textAnnotation->set_Border(border);
textAnnotation->set_Rect(rect);

page->get_Annotations()->Add(textAnnotation);
document->Save(_dataDir + u"sample_textannot.pdf");