品易云推流 关闭
文章详情页
文章 > java基础 > Java如何在PDF添加注释

Java如何在PDF添加注释

java PDF

头像

小妮浅浅

2021-07-13 09:48:372823浏览 · 0收藏 · 0评论

流程

1、使用Document类加载PDF文档。

2、创建TextAnnotation对象,添加文本注释。

3、设定标题、主题等注释属性。

4、使用Border类设置注释的Border。

使用Document.getPages().get_Item(int).getAnnotations().add(Annotation)方法向文档添加注释。

5、用Document.save保存更新的PDF。

实例

// Open the source PDF document
Document pdfDocument = new Document("input.pdf");
 
// Create annotation
TextAnnotation textAnnotation = new TextAnnotation(pdfDocument.getPages().get_Item(1), new com.aspose.pdf.Rectangle(200, 400, 400, 600));
 
// Set annotation title
textAnnotation.setTitle("Sample Annotation Title");
 
// Set annotation subject
textAnnotation.setSubject("Sample Subject");
textAnnotation.setState(AnnotationState.Accepted);
 
// Specify the annotation contents
textAnnotation.setContents("Sample contents for the annotation");
textAnnotation.setOpen(true);
textAnnotation.setIcon(TextIcon.Key);
Border border = new Border(textAnnotation);
border.setWidth(5);
border.setDash(new Dash(1, 1));
textAnnotation.setBorder(border);
textAnnotation.setRect(new com.aspose.pdf.Rectangle(200, 400, 400, 600));
 
// Add annotation in the annotations collection of the page
pdfDocument.getPages().get_Item(1).getAnnotations().add(textAnnotation);
 
// Save the output file
pdfDocument.save("output.pdf");

以上就是Java在PDF添加注释的方法,希望对大家有所帮助。更多Java学习指路:Java基础

本教程操作环境:windows7系统、java10版,DELL G3电脑。

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图