使用C#管理 PDF 中的批注

現代 C# 庫,用於使用我們的 API 管理 PDF 註釋。

如何使用 .NET 庫管理批注

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

Package Manager Console

PM > Install-Package Aspose.PDF

通過C#在 PDF 文件中創建批注


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

  1. 在文件類的實例中載入 PDF。
  2. 建立要添加到 PDF 中的批注。
  3. 將批註添加到 Page 物件的批注集合中。
  4. 保存 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);