使用 C++ 管理 PDF 中的注释

现代 C++ 库,用于使用我们的 API 管理 PDF 注释。

如何使用 C++ 库管理注释

为了在 PDF 文件中添加文本注释,我们将使用 Aspose.PDF for C++ API,这是一款功能丰富、功能强大且易于使用的适用于 cpp 平台的文档处理 API。打开 NuGet 软件包管理器,搜索 aspose.pdf 然后安装。您也可以从软件包管理器控制台使用以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

通过 C++ 在 PDF 文档中创建注释


你需要 Aspose.PDF for C++ 才能在你的环境中试用代码。

1.在 “文档” 类的实例中加载 PDF。 1.创建要添加到 PDF 的注释。 1.将注释添加到 Page 对象的 “注释” 集合中。 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");
}