使用 C# 管理 PDF 中的注释

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

如何使用 .NET 库管理注释

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

Package Manager Console

PM > Install-Package Aspose.PDF

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


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

1.在 “文档” 类的实例中加载 PDF。 1.创建要添加到 PDF 的注释。 1.将注释添加到 Page 对象的 “注释” 集合中。 1.保存 PDF 文件。

PDF 文本注释-C#。

Example: C#


    Document pdfDocument = new Document(dataDir + "AddAnnotation.pdf");
    TextAnnotation textAnnotation = new TextAnnotation(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(200, 400, 400, 600));
    textAnnotation.Title = "Sample Annotation Title";
    textAnnotation.Subject = "Sample Subject";
    textAnnotation.State = AnnotationState.Accepted;
    textAnnotation.Contents = "Sample contents for the annotation";
    textAnnotation.Open = true;
    textAnnotation.Icon = TextIcon.Key;
    Border border = new Border(textAnnotation);
    border.Width = 5;
    border.Dash = new Dash(1, 1);
    textAnnotation.Border = border;
    textAnnotation.Rect = new Aspose.Pdf.Rectangle(200, 400, 400, 600);
    pdfDocument.Pages[1].Annotations.Add(textAnnotation);
    dataDir = dataDir + "AddAnnotation_out.pdf";
    pdfDocument.Save(dataDir);