怎么用Java代码在PDF中添加注释
作者:BlueNight
时间:2023-04-25
来源:互联网
浏览:0
流程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");
作者最新文章
联发科天玑9600 Pro首发2nm:能效与游戏渲染技术详解
2026-09-08 16:54
Excel基础操作指南:数据录入、格式设置、公式应用与打印预览
2026-09-02 12:47
动画制作全流程:从故事板到关键帧与最终输出
2026-09-02 11:12
砸了百亿的“神器”,正在很多人家里吃灰
2026-08-25 15:53
REDMI 17与Note 17系列通过认证 Note 17系列或7、8月发布
2026-08-25 14:28
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多
Windows 10
Windows
Windows 10 是一款微软推出的经典操作系统,拥有硬件兼容性与多任务处理能力。它更偏向把系统状态查看和常用调节动作放在一起,适合需要持续观察和微调设备状态的场景。
极度公式
Windows/macOS/Linux
极度公式是一款跨平台专业LaTeX公式识别编辑软件,支持OCR公式识别和多平台编辑。和使用说明,避免使用,享受完整功能与稳定支持。做扫描整理、文字提取和表格转换时,它能把识别后的处理步骤接得更顺,资料录入这类场景会省下不少时间。
















