Manage Annotations in PDF via Java

Managing annotations in PDF document. Use Aspose.PDF for Java to modify PDF files programmatically

How to Manage Annotations Using Java Library

In order to add Text Annotation, we’ll use Aspose.PDF for Java API which is a feature-rich, powerful and easy to use conversion API for Java platform. You can download its latest version directly from Maven and install it within your Maven-based project by adding the following configurations to the pom.xml.


    <name>Aspose Java AP</name>


<version>version of aspose-pdf API</version>

Create Annotations in PDF document via Java

You need Aspose.PDF for Java to try the code in your environment.

  1. Load PDF in an instance of Document class.
  2. Create an annotation that you want to add to the PDF.
  3. Add the annotation to the Page object’s Annotations collection.
  4. Save the PDF file.

PDF Text Annotation - Java

Example: Java

    Document document = new Document(_dataDir + "sample.pdf");
    Page page = document.getPages().get_Item(1);
    Rectangle rect = new Rectangle(200, 750, 400, 790);
    TextAnnotation textAnnotation = new TextAnnotation(page, rect);

    textAnnotation.setTitle("Aspose User");
    textAnnotation.setSubject("Sample Subject");
    textAnnotation.setState (AnnotationState.Accepted);
    textAnnotation.setContents("Sample contents for the annotation");

    Border border = new Border(textAnnotation);
    border.setDash(new Dash(1, 1));

    page.getAnnotations().add(textAnnotation); + "sample_textannot.pdf");