> 文章列表 > Aspose.Pdf 使用教程:在现有的PDF文件中添加注释

Aspose.Pdf 使用教程:在现有的PDF文件中添加注释

Aspose.Pdf 使用教程:在现有的PDF文件中添加注释

Aspose.PDF 是一款高级PDF处理API,可以在跨平台应用程序中轻松生成,修改,转换,呈现,保护和打印文档。无需使用Adobe Acrobat。此外,API提供压缩选项,表创建和处理,图形和图像功能,广泛的超链接功能,图章和水印任务,扩展的安全控件和自定义字体处理。本文将为你介绍如何在 C++ 中将PDF转换为Doc 、Docx 。

Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。 

这个地方的所说的注释包含在每个特定页的注释集中。因为每个PDF页都有自己单独的注释集,所以这个注释集也只是收录这个PDF页中的注释。要在一个PDF页中使用Aspose.Pdf添加注释,必须要使用Add方法将这个需要添加的注释添加到Annotations注释集中。所以第一步是创建一个新的注释,然后打开PDF文件,将之添加到该页的注释集中。

下面是具体的代码示例:

C#

//open document
Document pdfDocument = new Document("input.pdf");
//create annotation
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);
//add annotation in the annotations collection of the page
pdfDocument.Pages[1].Annotations.Add(textAnnotation);
save output file
pdfDocument.Save("output.pdf");

VB.NET

'open document
Dim pdfDocument As New Document("input.pdf")
'create annotation
Dim textAnnotation As 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
Dim border As 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)
'add annotation in the annotations collection of the page
pdfDocument.Pages(1).Annotations.Add(textAnnotation)
'//save output file
pdfDocument.Save("output.pdf") 

以上便是如何在现有的PDF文件中添加注释,要是您还有其他关于产品方面的问题,欢迎咨询我们