PDF处理控件Aspose.PDF功能演示:使用C#在PDF文件中添加或删除注释

  • 使用C#将注释添加到PDF
  • 在C#中从PDF删除注释

为了在.NET应用程序中使用PDF文档,Aspose提供了

PDF处理控件Aspose.PDF功能演示:使用C#在PDF文件中添加或删除注释

整合所有格式API处理控件Aspose.Total永久授权火热促销中,联系客服立马1分钟了解全部!


使用C#将注释添加到PDF

PDF格式支持各种类型的注释,例如文本,线条,圆形,正方形,修订等。为了与每个PDF注释一起使用,Aspose.PDF for .NET提供了单独的类。例如,LineAnnotation类用于添加行,而HighlightAnnotation类用于添加突出显示注释。让我们看一下在PDF文档中添加任何类型的注释的步骤。

使用C#在PDF中添加注释的步

  • 使用Document类加载PDF文件。
  • 创建所需注释类的实例,即HighlightAnnotation或LineAnnotation。
  • 设置注释的属性,例如位置,颜色,大小等。
  • 使用Document.Pages [1] .Annotations.Add(Annotation)方法将注释添加到特定PDF页面的Annotations集合中。
  • 使用Document.Save(String)方法保存PDF文档。

为了演示,下面的代码示例演示如何使用C#将行注释添加到PDF。

// Load the PDF fileDocument document = new Document("Input.pdf");// Create Line Annotationvar lineAnnotation = new LineAnnotation(document.Pages[1],new Rectangle(550, 93, 562, 439),new Point(556, 99), new Point(556, 443)){Title = "John Smith",Color = Color.Red,Width = 3,StartingStyle = LineEnding.OpenArrow,EndingStyle = LineEnding.OpenArrow,Popup = new PopupAnnotation(document.Pages[1], new Rectangle(842, 124, 1021, 266))};// Add annotation to the pagedocument.Pages[1].Annotations.Add(lineAnnotation);// Save PDFdocument.Save("output.pdf");

在C#中从PDF删除注释

可以使用Aspose.PDF for .NET从现有PDF文档中删除PDF批注。您可以从PDF删除全部或特定注释。以下是删除PDF注释的步骤。

  • 使用Document类加载PDF文件。
  • 使用Document.Pages [index] .Annotations.Delete()方法删除特定页面上的所有注释。
  • 或使用Document.Pages [index] .Annotations.Delete(Int index)或Document.Pages [index] .Annotations.Delete(Annotation)方法删除特定的注释。
  • 使用Document.Save(String)方法保存文档。

下面的代码示例演示如何使用C#从PDF文件中删除注释。

// Open documentDocument pdfDocument = new Document("DeleteAnnotationsFromPage.pdf");// Delete particular annotationpdfDocument.Pages[1].Annotations.Delete();// Or delete particular annotation// pdfDocument.Pages[1].Annotations.Delete(1);// Save updated documentpdfDocument.Save("output.pdf");


还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月4日
下一篇 2021年1月4日

相关推荐

发表回复

登录后才能评论