Add image annotation

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:

  1. Instantiate the Annotator class. Specify the input document path or stream.
  2. Instantiate the ImageAnnotation class. Specify the appropriate properties (position, page number, etc).
  3. Call the Add method. Specify the ImageAnnotation class.
  4. 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");
}

On this page