Add Annotation to PDF

Add Text Annotation

To add an annotation:

  1. Open the input PDF.
  2. Create the annotation you want to add.
  3. Add the annotation to Annotations collection of the page you want to add it to.

The following code snippet shows how to add an annotation to a PDF page.

Cross, circle and star values are also added to the com.aspose.pdf.TextIcon enumeration.

Invisible Annotation

Sometimes, it is necessary to create a watermark that isn’t visible in the document when viewing it but should be visible when the document is printed. Use annotation flags for this purpose. The following code snippet shows how to accomplish this requirement.

Add Watermark Annotation

You can add Watermark Text using WatermarkAnnotation at specific position of PDF page, opacity of Watermark can also controlled by using opacity property. Please check following code snippet to add WatermarkAnnotation.


 //Load a Document

com.aspose.pdf.Document doc = new com.aspose.pdf.Document(myDir+"HelloWorld.pdf");

//Load Page object to add Annotation

Page page = doc.getPages().get_Item(1);

//Create Annotation

WatermarkAnnotation wa = new WatermarkAnnotation(page, new com.aspose.pdf.Rectangle(100, 500, 400, 600));

//Add annotation into Annotation collection of Page


//Create TextState for Font settings

com.aspose.pdf.TextState ts = new com.aspose.pdf.TextState();


ts.setFont(FontRepository.findFont("Times New Roman"));


//Set opacity level of Annotation Text


//Add Text in Annotation

wa.setTextAndState(new String[] { "HELLO", "Line 1", "Line 2" }, ts);

//Save the Document"Output.pdf");