使用 C# 管理 PDF 中的註釋

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

如何使用 .NET 程式庫管理註釋

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

Package Manager Console

PM > Install-Package Aspose.PDF

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


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

1.在文件類別的執行個體中載入 PDF。 1.建立您要新增至 PDF 的註解。 1.將註釋加入到「頁面」物件的「註釋」集合中。 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);