
流程
1、使用Document类加载PDF文档。
2、创建TextAnnotation对象,添加文本注释。
3、设定标题、主题等注释属性。
4、使用Border类设置注释的Border。
使用Document.getPages().get_Item(int).getAnnotations().add(Annotation)方法向文档添加注释。
5、用Document.save保存更新的PDF。
实例
//OpenthesourcePDFdocument
DocumentpdfDocument=newDocument("input.pdf");
//Createannotation
TextAnnotationtextAnnotation=newTextAnnotation(pdfDocument.getPages().get_Item(1),newcom.aspose.pdf.Rectangle(200,400,400,600));
//Setannotationtitle
textAnnotation.setTitle("SampleAnnotationTitle");
//Setannotationsubject
textAnnotation.setSubject("SampleSubject");
textAnnotation.setState(AnnotationState.Accepted);
//Specifytheannotationcontents
textAnnotation.setContents("Samplecontentsfortheannotation");
textAnnotation.setOpen(true);
textAnnotation.setIcon(TextIcon.Key);
Borderborder=newBorder(textAnnotation);
border.setWidth(5);
border.setDash(newDash(1,1));
textAnnotation.setBorder(border);
textAnnotation.setRect(newcom.aspose.pdf.Rectangle(200,400,400,600));
//Addannotationintheannotationscollectionofthepage
pdfDocument.getPages().get_Item(1).getAnnotations().add(textAnnotation);
//Savetheoutputfile
pdfDocument.save("output.pdf");
以上就是Java在PDF添加注释的方法,希望对大家有所帮助。更多Java学习指路:Java基础
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
















































暂无评论内容