---
title: "Read PDF review annotations in C#"
url: https://recursiveai.org/onediff/cookbook/read-review-highlights-from-pdf/
description: "Read highlight comments from a OneDiff-marked PDF in C#. The runnable example prints the page number and the old text."
version: "1.0.1"
---

# Read PDF review annotations in C#

**OneDiff** is a free, open-source diff library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneDiff.Pdf) · [GitHub](https://github.com/recursive-ai-oss/onediff-csharp) · [Docs](https://recursiveai.org/onediff/docs/) · [Download example (.zip)](https://recursiveai.org/onediff/cookbook/read-review-highlights-from-pdf/read-review-highlights-from-pdf.zip)

Read the highlight comments in `marked.pdf`, a OneDiff review PDF included in the zip. `page.Annotations` isn’t limited to OneDiff output: it also read the highlight comment in a PDF marked with a separate tool.

```shell
dotnet add package RecursiveAI.OneDiff.Pdf
```

This package includes OnePDF as a dependency, so the snippet uses `using OnePdf;`.

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OnePdf;
using var pdf = PdfDocument.Open("marked.pdf");
foreach (var page in pdf.Pages)
foreach (var mark in page.Annotations)
    if (mark.Subtype == "Highlight")
        Console.WriteLine(mark.Contents);
```

Unzip [the example](https://recursiveai.org/onediff/cookbook/read-review-highlights-from-pdf/read-review-highlights-from-pdf.zip), then `dotnet run`.

Prints:

```text
+ Replaced
30 days
```

## The full program

```csharp
using OnePdf;

string path = args.Length == 0 ? "marked.pdf" : args[0];
using var pdf = PdfDocument.Open(path);
int count = 0;
for (int i = 0; i < pdf.PageCount; i++)
{
    foreach (var mark in pdf.Pages[i].Annotations)
    {
        if (mark.Subtype != "Highlight") continue;
        Console.WriteLine($"Page {i + 1}:");
        Console.WriteLine(mark.Contents);
        count++;
    }
}
Console.WriteLine($"Highlights: {count}");
```

```text
Page 1:
+ Replaced
30 days
Highlights: 1
```

The included `marked.pdf` is a generated one-page sample. Its visible text is “Pay in 60 days.” The comparison against “Pay in 30 days.” highlighted the replacement and put the old text in the highlight comment. To read a different PDF, run `dotnet run -- review.pdf`. A page without highlight annotations contributes nothing to the count; if there are none anywhere, the program prints `Highlights: 0`.

## Variations

**Count the marked areas.** Inside the highlight loop, print the number of quadrilaterals: each is a four-cornered area represented by eight coordinates.

```csharp
Console.WriteLine(mark.QuadPoints.Count / 8);
```

**Read other text markup too.** Replace the full program’s subtype check with this one if you also want strikeouts, underlines, and wavy underlines:

```csharp
if (mark.Subtype is not ("Highlight" or "StrikeOut"
    or "Underline" or "Squiggly")) continue;
```

## Related recipes

- [Compare PDFs and highlight differences](https://recursiveai.org/onediff/cookbook/compare-pdf-highlight-changes/)
- [Create a redline PDF from text documents](https://recursiveai.org/onediff/cookbook/render-text-document-redline-as-pdf/)

## The short answer

Open the marked file with `PdfDocument.Open`, loop over `page.Annotations`, and select the `Highlight` subtype. `Contents` holds the highlight comment, if present. You only need the marked PDF for this step, not both files from the original comparison.

## How do you read PDF annotations without extracting the whole page?

Annotations are available separately from page text. Start with the page index and the annotation subtype, then read the highlight comment, if present. If you want to place the mark on a preview, keep the page index and `QuadPoints` as well. One highlight can have more than one marked area, for example when the text crosses a line break. The variation counts areas on each highlight, not how many highlights the page has.

The highlight comment is not the highlighted text. In this sample, `Contents` starts with `+ Replaced` and then gives `30 days`; the annotated page is the newer version, which says `60 days`. To recover what the mark covers rather than what the highlight comment says, you need to match the highlight geometry against extracted page text. As the [OneDiff PDF documentation](https://recursiveai.org/onediff/docs/pdf/) describes, OneDiff can round part of a changed word out to a whole word when drawing the mark, so geometry and the exact text change are not interchangeable.

## Why might a PDF show highlights but have no highlight annotations?

In OneDiff, original-page markup adds annotations to the newer PDF. A rendered redline instead draws its changes as part of a newly laid-out report. Both can show colored changes in a viewer, but the loop above reads the annotation objects, not the colors drawn on a page. If you control how the review PDF is created and need to read its notes later, use original-page markup rather than the rendered report.
