怎么用Java代码在PDF中添加注释
作者:BlueNight
时间:2023-04-27
浏览:7
流程1、使用Document类加载PDF文档。2、创建TextAnnotation对象,添加文本注释。3、设定标题、主题等注释属性。4、使用Border类设置注释的Border。使用Document.getPages().get_Item(int).getAnnotations().add(Annotation)方法向文档添加注释。5、用Document.save保存更新的PDF。实例//OpenthesourcePDFdocumentDocumentpdfDocument=newDocument("in
本文目录
流程
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");
作者最新文章
TapTap怎么查看玩过的游戏记录 入口在哪
2026-11-21 16:45
搜狗输入法电脑端麦克风检测不到 声音设置排查
2026-11-19 10:59
Claude Fable 5.2与Mythos 5.2短时过载已缓解:故障范围与重试排查
2026-11-12 17:11
office无法安装0-2060 安装步骤和注意事项
2026-11-02 15:45
立刻MV苹果端最新版本更新了哪些功能?使用变化解析
2026-10-31 13:24
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多

































