How to add comments to PDF by Java
This article mainly explains "Java how to add comments in PDF", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Java how to add comments in PDF" bar!
Process flow
1. Use the Document class to load the PDF document.
2. Create a TextAnnotation object and add text comments.
3. Set the title, theme and other annotation attributes.
4. Use the Border class to set the Border of the annotation.
Use the Document.getPages () .get_Item (int) .getAnnotations () .add (Annotation) method to add comments to the document.
5. Save the updated PDF with Document.save.
Example
/ / Open the source PDF documentDocument pdfDocument = new Document ("input.pdf"); / / Create annotationTextAnnotation textAnnotation = new TextAnnotation (pdfDocument.getPages (). Get_Item (1), new com.aspose.pdf.Rectangle (200,400,400,600); / / Set annotation titletextAnnotation.setTitle ("Sample Annotation Title"); / / Set annotation subjecttextAnnotation.setSubject ("Sample Subject"); textAnnotation.setState (AnnotationState.Accepted); / / Specify the annotation contentstextAnnotation.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 pagepdfDocument.getPages (). Get_Item (1). GetAnnotations (textAnnotation); / / Save the output filepdfDocument.save (output.pdf) Thank you for your reading, the above is the content of "Java how to add comments in PDF", after the study of this article, I believe you have a deeper understanding of how Java adds comments in PDF, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!