Annotations

Body Content: Use a PdfDocument object's AnnotationManager, along with the AnnotationOptions class from IronPDF, to add "sticky note"-style annotations to specified pages of a PDF document.

Create a text-based annotation at a given location on a page by specifying the text and the Cartesian (x, y) coordinates as arguments in an AnnotationOptions constructor, as shown in the code example below. Next, invoke the addTextAnnotation method on the AnnotationManager to add the annotation to the desired page in the working PDF document.

Additional methods on every AnnotationOptions object enable developers to customize an annotation's appearance and behavior. In the code example below, we set its opacity and featured icon, as well as configure it to be neither editable nor printable. Developers can also change the color, height, and title of an annotation, as well as its title, subject, content, and location.

// Import necessary IronPDF classes
import com.ironpdf.*;

public class PdfAnnotationExample {
    public static void main(String[] args) {
        // Load an existing PDF document
        PdfDocument pdf = PdfDocument.load("example.pdf");

        // Create an instance of AnnotationOptions with text and position
        AnnotationOptions annotationOptions = new AnnotationOptions("This is a sticky note", 100, 100);

        // Further customize the annotation. For example, change opacity and set icon type
        annotationOptions.setOpacity(0.5);
        annotationOptions.setIconType(AnnotationIconType.NOTE);

        // Make the annotation non-editable and non-printable
        annotationOptions.setEditable(false);
        annotationOptions.setPrintable(false);

        // Retrieve the AnnotationManager from the PdfDocument
        AnnotationManager annotationManager = pdf.getAnnotationManager();

        // Add the annotation to the first page
        annotationManager.addTextAnnotation(1, annotationOptions);

        // Save the updated document with annotations
        pdf.saveAs("annotated_example.pdf");
    }
}
// Import necessary IronPDF classes
import com.ironpdf.*;

public class PdfAnnotationExample {
    public static void main(String[] args) {
        // Load an existing PDF document
        PdfDocument pdf = PdfDocument.load("example.pdf");

        // Create an instance of AnnotationOptions with text and position
        AnnotationOptions annotationOptions = new AnnotationOptions("This is a sticky note", 100, 100);

        // Further customize the annotation. For example, change opacity and set icon type
        annotationOptions.setOpacity(0.5);
        annotationOptions.setIconType(AnnotationIconType.NOTE);

        // Make the annotation non-editable and non-printable
        annotationOptions.setEditable(false);
        annotationOptions.setPrintable(false);

        // Retrieve the AnnotationManager from the PdfDocument
        AnnotationManager annotationManager = pdf.getAnnotationManager();

        // Add the annotation to the first page
        annotationManager.addTextAnnotation(1, annotationOptions);

        // Save the updated document with annotations
        pdf.saveAs("annotated_example.pdf");
    }
}
JAVA

Steps to create an Annotation in a PDF using Java

  1. Install the IronPDF Java library to add annotations to PDF documents.
  2. Utilize the PdfDocument class to load an existing PDF file in Java.
  3. Create and customize annotations with the AnnotationOptions class.
  4. Use addTextAnnotation from IronPDF to add annotations to specific pages of the PDF.
  5. Export the PDF document containing annotations.

For more information on how to get started with annotations in PDFs using IronPDF, visit the IronPDF Documentation.