这篇文章主要讲解了“Java怎么在PDF中添加注释”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Java怎么在PDF中添加注释”吧!
流程
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怎么在PDF中添加注释这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://www.py.cn/java/jichu/29035.html