---
title: "Adding annotations to a PDF document | Nutrient Java SDK"
canonical_url: "https://www.nutrient.io/guides/java/editor/add-annotations-to-pdf/"
md_url: "https://www.nutrient.io/guides/java/editor/add-annotations-to-pdf.md"
last_updated: "2026-06-09T10:26:34.600Z"
description: "How to add annotations to a PDF using Nutrient Java SDK."
---

# Adding annotations to a PDF document

Use annotations to add comments, markup, stamps, and links to PDF documents.

Common use cases include:

- Review and approval workflows

- Team collaboration and feedback

- Programmatic document markup

- Navigation links inside and outside a document

[Download sample](https://www.nutrient.io/downloads/samples/java/add-annotations-to-pdf.zip)

## How Nutrient helps

Nutrient Java SDK handles annotation structures and appearance generation.

The SDK handles:

- Parsing annotation dictionaries and appearance streams

- Managing annotation flags and border styles

- Handling coordinate transformations and bounding box calculations

- Complex annotation state management and reply chains

## Complete implementation

This example adds several annotation types to a PDF:

```java

package io.nutrient.Sample;

import io.nutrient.sdk.Document;
import io.nutrient.sdk.types.Color;
import io.nutrient.sdk.editors.PdfEditor;
import io.nutrient.sdk.editors.pdf.pages.PdfPageCollection;
import io.nutrient.sdk.editors.pdf.pages.PdfPage;
import io.nutrient.sdk.editors.pdf.annotations.PdfAnnotationCollection;
import io.nutrient.sdk.editors.pdf.annotations.PdfAnnotation;
import io.nutrient.sdk.editors.pdf.annotations.PdfTextAnnotation;
import io.nutrient.sdk.editors.pdf.annotations.PdfHighlightAnnotation;
import io.nutrient.sdk.editors.pdf.annotations.PdfUnderlineAnnotation;
import io.nutrient.sdk.editors.pdf.annotations.PdfStrikeOutAnnotation;
import io.nutrient.sdk.editors.pdf.annotations.PdfSquigglyAnnotation;
import io.nutrient.sdk.editors.pdf.annotations.PdfStampAnnotation;
import io.nutrient.sdk.editors.pdf.annotations.PdfLinkAnnotation;

public class AddAnnotationsToPdf {

```

Create the `main` method as the sample entry point:

```java

    public static void main(String[] args) {

```

Open the document with try-with-resources, create an editor, and ensure one page exists:

```java

        try (Document document = Document.open("input.pdf")) {
            PdfEditor editor = PdfEditor.edit(document);
            PdfPageCollection pages = editor.getPageCollection();

            if (pages.getCount() == 0) {
                pages.add(612.0f, 792.0f);
            }

            PdfPage page = pages.getFirst();
            PdfAnnotationCollection annotations = page.getAnnotationCollection();

```

`annotations` is bound to `page = pages.getFirst()`, so all annotations added through this collection are created on that first page.

Add a sticky note with position, author, subject, and contents.

In this sample:

- The position is `(100, 700)`.

- The color is set to yellow with ARGB values.

```java

            PdfTextAnnotation stickyNote = annotations.addStickyNote(
                100.0f, 700.0f,  // x, y
                "Test Author",
                "Test Subject",
                "This is a sticky note comment"
            );
            // Customize the color
            stickyNote.setColor(Color.fromArgb(255, 255, 255, 0));

```

Add text markup annotations: highlight, underline, strikeout, and squiggly.

Each annotation uses:

- `x`, `y`, `width`, `height` for placement

- Author and contents metadata

- Optional color customization

```java

            PdfHighlightAnnotation highlight = annotations.addHighlight(
                50.0f, 600.0f, 150.0f, 20.0f,  // x, y, width, height
                "Highlighter",
                "Highlighted text area"
            );
            highlight.setColor(Color.fromArgb(128, 255, 255, 0));

            PdfUnderlineAnnotation underline = annotations.addUnderline(
                50.0f, 550.0f, 150.0f, 20.0f,  // x, y, width, height
                "Underliner",
                "Underlined text area"
            );
            underline.setColor(Color.fromArgb(255, 0, 0, 255));

            PdfStrikeOutAnnotation strikeOut = annotations.addStrikeOut(
                50.0f, 500.0f, 150.0f, 20.0f,  // x, y, width, height
                "Striker",
                "Struck out text area"
            );
            strikeOut.setColor(Color.fromArgb(255, 255, 0, 0));

            PdfSquigglyAnnotation squiggly = annotations.addSquiggly(
                50.0f, 450.0f, 150.0f, 20.0f,  // x, y, width, height
                "Squiggler",
                "Squiggly underlined area"
            );
            squiggly.setColor(Color.fromArgb(255, 0, 128, 0));

```

Add a stamp annotation for status-style markup.

In this sample:

- The position is `(300, 600)`.

- The size is `100 × 50`.

- The color is set to purple.

```java

            PdfStampAnnotation stamp = annotations.addStamp(
                300.0f, 600.0f, 100.0f, 50.0f,  // x, y, width, height
                "Stamp Title",
                "Stamp contents"
            );
            // Customize the color
            stamp.setColor(Color.fromArgb(255, 128, 0, 128));

```

Add two link annotation types:

- External URI link with `setURI()`

- Internal page destination link with `setDestination()`

Even after adding a new page, `annotations` still points to the first page (`pages.getFirst()`), so the new link annotation is created on the original first page.

```java

            PdfLinkAnnotation link = annotations.addLink(
                300.0f, 500.0f, 200.0f, 20.0f  // x, y, width, height
            );
            link.setURI("https://www.nutrient.io");

            pages.add(612.0f, 792.0f);
            PdfLinkAnnotation pageLink = annotations.addLink(
                300.0f, 450.0f, 200.0f, 20.0f  // x, y, width, height
            );
            pageLink.setDestination(2, 0.0f, 792.0f);

```

Iterate over annotations, inspect types, remove one by index, and then save:

Iteration includes existing annotations already present in the input PDF plus the annotations added in this sample, so the printed list can contain more items or types than the newly created annotations alone.

`removeAt(0)` removes whichever annotation is currently first on that page. If the input PDF already contains annotations, it may remove an existing annotation rather than one added in this sample.

```java

            for (PdfAnnotation annot : annotations) {
                System.out.println("Annotation: " + annot.getClass().getSimpleName());
            }

            annotations.removeAt(0);

            editor.saveAs("output.pdf");
            editor.close();
        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

```

## Conclusion

Use this workflow to add annotations:

1. Open the document and create an editor.

2. Access the page collection and ensure at least one page exists.

3. Retrieve the annotation collection for the target page.

4. Add sticky note annotations with author and comment metadata.

5. Add text markup annotations (highlight, underline, strikeout, squiggly) with positioning and colors.

6. Add stamp annotations for document status indication.

7. Add link annotations for external URIs and internal page navigation.

8. Iterate through annotations for processing or filtering.

9. Remove annotations by index position.

10. Save and close the editor.

For related annotation workflows, refer to the [Java SDK guides](https://www.nutrient.io/guides/java.md).
---

## Related pages

- [Adding a custom page to a PDF document](/guides/java/editor/add-custom-page-to-pdf.md)
- [Adding interactive form fields to a PDF document](/guides/java/editor/add-form-fields-to-pdf.md)
- [Adding invisible digital signatures to a PDF document](/guides/java/editor/add-invisible-signature-to-pdf.md)
- [Adding free text annotations to a PDF document](/guides/java/editor/add-freetext-annotations-to-pdf.md)
- [Adding link annotations to a PDF document](/guides/java/editor/add-link-annotations-to-pdf.md)
- [Adding shape annotations to a PDF document](/guides/java/editor/add-shape-annotations-to-pdf.md)
- [Adding stamp annotations to a PDF document](/guides/java/editor/add-stamp-annotations-to-pdf.md)
- [Adding text markup annotations to a PDF document](/guides/java/editor/add-text-markup-annotations-to-pdf.md)
- [Adding sticky note annotations to a PDF document](/guides/java/editor/add-sticky-note-annotations-to-pdf.md)
- [Detecting and adding form fields to a PDF document](/guides/java/editor/detect-and-add-form-fields.md)
- [Adding visible digital signatures to a PDF document](/guides/java/editor/add-visible-signature-to-pdf.md)
- [Advanced digital signature workflows](/guides/java/editor/advanced-digital-signatures.md)
- [Adding redaction annotations to a PDF document](/guides/java/editor/add-redaction-annotations-to-pdf.md)
- [Editing PDF form fields](/guides/java/editor/editing-pdf-form-fields.md)
- [Editing PDF metadata with Nutrient Java SDK](/guides/java/editor/editing-pdf-metadata.md)
- [Merging PDFs](/guides/java/editor/merge-pdf-into-other-pdf.md)
- [Filling PDF form fields](/guides/java/editor/fill-pdf-form.md)
- [Nutrient Java SDK editor guides](/guides/java/editor.md)
- [Managing PDF page order](/guides/java/editor/manage-pdf-page-order.md)

