使用 C# 管理 PDF 中的批注

管理 PDF 文档中的注释。使用 Aspose.PDF for .NET 以编程方式修改 PDF 文件

如何使用 .NET 库管理注释

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

Package Manager Console

PM > Install-Package Aspose.PDF

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


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

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

PDF 文本注释-C#

Example: C#

var inputFile = Path.Combine(dataDir, "AddAnnotation.pdf");
var outputFile = Path.Combine(dataDir, "AddAnnotation_out.pdf");

var pdfDocument = new Aspose.Pdf.Document(inputFile);
var textAnnotation =
    new Aspose.Pdf.Annotations.TextAnnotation(pdfDocument.Pages[1],
    new Aspose.Pdf.Rectangle(200, 400, 400, 600))
    {
        Title = "Sample Annotation Title",
        Subject = "Sample Subject"
    };
textAnnotation.SetReviewState(Aspose.Pdf.Annotations.AnnotationState.Accepted,"user");
textAnnotation.Contents = "Sample contents for the annotation";
textAnnotation.Open = true;
textAnnotation.Icon = Aspose.Pdf.Annotations.TextIcon.Key;

var border = new Aspose.Pdf.Annotations.Border(textAnnotation)
{
    Width = 5,
    Dash = new Aspose.Pdf.Annotations.Dash(1, 1)
};
textAnnotation.Border = border;
textAnnotation.Rect =
    new Aspose.Pdf.Rectangle(200, 400, 400, 600);
pdfDocument.Pages[1].Annotations.Add(textAnnotation);
        
pdfDocument.Save(outputFile);