Add image annotation
Leave feedback
On this page
Image annotation allows you to add an image on document page as shown in the picture below:
You can set the following properties of the ImageAnnotation class:
- ImagePath defines the image local or remote path
- Box defines the annotation position on the page using the Rectangle structure (image will be resized for specified width and height)
- Opacity allows you to set the annotation opacity (present in all supported formats, examples of it you can see above)
- Angle defines the annotation rotation angle
To add an image annotation, follow these steps:
- Instantiate the Annotator class. Specify the input document path or stream.
- Instantiate the ImageAnnotation class. Specify the appropriate properties (position, page number, etc).
- Call the Add method. Specify the ImageAnnotation class.
- Call the Save method. Specify the output document path or stream.
The following code snippet shows how to add ImageAnnotation to the document:
try(final Annotator annotator = new Annotator("input.pdf")){
ImageAnnotation imageAnnotation = new ImageAnnotation();
imageAnnotation.setBox(new Rectangle(100, 100, 100, 100));
imageAnnotation.setOpacity(0.7);
imageAnnotation.setPageNumber(0);
imageAnnotation.setImagePath("www.google.com.ua/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png");
imageAnnotation.setAngle(100.);
annotator.add(imageAnnotation);
annotator.save("result_image_annotation.pdf");
}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.