Adding text markup annotations to a PDF document
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
How Nutrient helps
Nutrient .NET SDK handles text markup annotation structures and appearance generation.
The SDK handles:
- Text markup dictionaries and quadrilateral arrays
- Translucent overlays and blend modes
- Coordinate calculations and bounding box intersections
- Appearance streams and color transformations
Complete implementation
This example adds several text markup annotations to a PDF file:
using Nutrient;Working with text markup annotations
Open the document with using statements(opens in a new tab) so resources are cleaned up after processing.
Then:
- Create a PDF editor.
- Get the page collection.
- Add a letter-size page (
612 × 792) if the document is empty. - Get the annotation collection from the first page.
try{ using Document document = Document.Open("input.pdf"); using PdfEditor editor = PdfEditor.Edit(document); PdfPageCollection pages = editor.PageCollection;
if (pages.Count == 0) { pages.Add(612.0f, 792.0f); }
PdfPage page = pages.First ?? throw new InvalidOperationException("The document has no pages."); PdfAnnotationCollection annotations = page.AnnotationCollection;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
128gives 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.Color = 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.Color = 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.Color = Color.FromArgb(255, 0, 128, 0);Saving the document
Save the output PDF.
The catch block catches NutrientException if processing fails:
editor.SaveAs("output.pdf"); Console.WriteLine("Successfully saved output.pdf");}catch (NutrientException e){ Console.Error.WriteLine($"Error: {e.Message}"); Environment.Exit(1);}Conclusion
Use this workflow to add text markup annotations:
- Open the document with
usingstatements for automatic resource cleanup. - Create an editor and access the page collection.
- Ensure at least one page exists by adding a letter-size page if needed.
- Retrieve the annotation collection from the target page.
- Add highlight annotations with translucent overlays using
AddHighlight()for emphasizing content. - Customize highlight transparency using ARGB alpha values (128 = 50 percent transparency).
- Add underline annotations with
AddUnderline()for drawing attention beneath text. - Add strikeout annotations with
AddStrikeOut()for marking deleted or outdated content. - Add squiggly annotations with
AddSquiggly()for indicating spelling or grammar issues. - Customize text markup colors using the
Colorproperty with ARGB color values. - Position annotations with consistent vertical spacing to create organized markup sequences.
- Save the document — the
usingstatements release the native handles.
For related annotation workflows, refer to the .NET SDK annotation guides.