文档彩票走势图>>Aspose.PDF使用教程>>Aspose.Pdf使用教程:在现有的PDF文件中添加注释
Aspose.Pdf使用教程:在现有的PDF文件中添加注释
这个地方的所说的注释包含在每个特定页的注释集中。因为每个PDF页都有自己单独的注释集,所以这个注释集也只是收录这个PDF页中的注释。要在一个PDF页中使用Aspose.Pdf添加注释,必须要使用Add方法将这个需要添加的注释添加到Annotations注释集中。所以第一步是创建一个新的注释,然后打开PDF文件,将之添加到该页的注释集中。
》》》下载Aspose.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")