這篇文章主要講解了“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中添加注釋這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。