Aspose.PDF FOSS for .NET 随附一套丰富的注释和表单字段 API,允许您在完全托管的代码中对 PDF 文档进行标注、链接和交互——无需许可证密钥。

注释概览

库的 AnnotationCollection 类为每个标准 PDF 注释提供了类型化的帮助方法。添加便签只需一次调用:

page.Annotations.AddTextAnnotation(
    new Rectangle(72, 720, 200, 740),
    contents: "Review needed",
    title: "Editor",
    open: true);

链接注释将可点击的矩形与 PdfAction 结合在一起:

var action = PdfAction.CreateUri("https://aspose.com");
page.Annotations.AddLinkAnnotation(
    new Rectangle(50, 700, 200, 720), action);

相同的模式适用于高亮、下划线、方框、圆形、线条和墨迹(手绘)批注 — 每种都有专用的 Add* 方法。

交互式表单字段

AcroForm 字段通过 Document.Form 访问。遍历 Form.Fields 读取字段值,或使用 Form 门面进行高级填充操作:

using var form = new Form("input.pdf", "output.pdf");
form.FillField("Name", "Alice");
form.Save();

字段子类包括 TextBoxFieldCheckboxFieldRadioButtonField, ComboBoxFieldListBoxFieldSignatureField

扁平化与访问者模式

调用 Annotation.Flatten() 将注释的视觉外观烧录到页面内容中。使用 AnnotationSelector 通过访问者模式按类型过滤注释——无需手动强制转换。

入门

使用以下方式安装:

dotnet add package Aspose.Pdf.Foss

有关分步指南,请参阅
Annotations and Forms developer guide
以及
how-to article


相关资源