Use text markup annotations to add review feedback directly on text in PDF files.

Common use cases include:

  • Proofreading workflows
  • Collaborative document review
  • Content highlighting and emphasis
  • Revision and deletion tracking

In this guide, you’ll add:

  • Highlight annotations
  • Underline annotations
  • Strikeout annotations
  • Squiggly annotations
  • Custom colors for each markup type
Download sample

How Nutrient helps

Nutrient Java SDK handles text markup annotation structures and appearance generation.

The SDK handles:

  • Parsing text markup annotation dictionaries and quadrilateral arrays
  • Managing translucent overlay rendering and blend modes
  • Handling text coordinate calculations and bounding box intersections
  • Complex annotation appearance streams and color transformations

Complete implementation

This example adds multiple text markup annotations to a PDF:

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.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;
public class TextMarkupAnnotations {

Create the main method as the sample entry point:

public static void main(String[] args) {

Working with text markup annotations

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

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();

Adding a highlight annotation

Add a highlight with addHighlight(x, y, width, height, author, contents).

In this sample:

  • The position is (50, 700).
  • The size is 150 × 20.
  • The color is set to translucent yellow with Color.fromArgb(128, 255, 255, 0).
  • The alpha value 128 gives 50 percent opacity.
PdfHighlightAnnotation highlight = annotations.addHighlight(
50.0f, 700.0f, 150.0f, 20.0f, // x, y, width, height
"Highlighter",
"Important information"
);
// Optionally customize the color
highlight.setColor(Color.fromArgb(128, 255, 255, 0));

Adding an underline annotation

Add an underline with addUnderline(x, y, width, height, author, contents).

In this sample:

  • The position is (50, 650).
  • The size is 150 × 20.
  • The color is set to blue with Color.fromArgb(255, 0, 0, 255).
PdfUnderlineAnnotation underline = annotations.addUnderline(
50.0f, 650.0f, 150.0f, 20.0f, // x, y, width, height
"Underliner",
"Emphasized text"
);
// Optionally customize the color
underline.setColor(Color.fromArgb(255, 0, 0, 255));

Adding a strikeout annotation

Add a strikeout with addStrikeOut(x, y, width, height, author, contents).

In this sample:

  • The position is (50, 600).
  • The size is 150 × 20.
  • The default color is red (ARGB 255, 255, 0, 0).
  • Use this style to mark text for removal.
PdfStrikeOutAnnotation strikeOut = annotations.addStrikeOut(
50.0f, 600.0f, 150.0f, 20.0f, // x, y, width, height
"Reviewer",
"This content should be removed"
);

Adding a squiggly annotation

Add a squiggly underline with addSquiggly(x, y, width, height, author, contents).

In this sample:

  • The position is (50, 550).
  • The size is 150 × 20.
  • The color is changed to green with Color.fromArgb(255, 0, 128, 0).
  • Use this style to flag spelling or grammar issues.
PdfSquigglyAnnotation squiggly = annotations.addSquiggly(
50.0f, 550.0f, 150.0f, 20.0f, // x, y, width, height
"Proofreader",
"Check spelling here"
);
// Optionally customize the color
squiggly.setColor(Color.fromArgb(255, 0, 128, 0));

Saving the document

Save the output PDF and close the editor:

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

Conclusion

Use this workflow to add text markup 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 highlight annotations with translucent overlays using addHighlight() for emphasizing content.
  5. Customize highlight transparency using ARGB alpha values (128 = 50 percent transparency).
  6. Add underline annotations with addUnderline() for drawing attention beneath text.
  7. Add strikeout annotations with addStrikeOut() for marking deleted or outdated content.
  8. Add squiggly annotations with addSquiggly() for indicating spelling or grammar issues.
  9. Customize text markup colors using setColor() with ARGB color values.
  10. Position annotations with consistent vertical spacing to create organized markup sequences.
  11. Save and close the editor.

For related annotation workflows, refer to the Java SDK guides.