Annotate documents with GroupDocs.Annotation

GroupDocs.Annotation adds review markup to documents — areas, arrows, highlights, strikeouts, text fields, watermarks and threaded replies — and reads back the annotations already on a file. It is the API behind a document review or collaboration feature.

Add an area annotation

An area annotation boxes a region of a page and attaches a comment to it. Box is the rectangle in points, and PageNumber is zero-based.

using GroupDocs.Annotation;
using GroupDocs.Annotation.Models;
using GroupDocs.Annotation.Models.AnnotationModels;

using (Annotator annotator = new Annotator("contract.pdf"))
{
    AreaAnnotation area = new AreaAnnotation
    {
        Box = new Rectangle(100, 100, 200, 100),
        BackgroundColor = 65535,
        Message = "Please confirm these figures",
        PageNumber = 0,
        Opacity = 0.7
    };

    annotator.Add(area);
    annotator.Save("annotation-add-area.pdf");
}

contract.pdf is the sample file used in this example. Click here to download it.

Binary file (PDF, 130 KB)

Download full output

Note
Colours are 32-bit integers, not Color values — 65535 is yellow. PageNumber counts from zero, so the first page is 0.

Highlight text

A highlight annotation is bounded by four corner Points rather than a rectangle, because a highlight can follow text that wraps across lines and is not always a neat box.

using System.Collections.Generic;
using GroupDocs.Annotation;
using GroupDocs.Annotation.Models;
using GroupDocs.Annotation.Models.AnnotationModels;

using (Annotator annotator = new Annotator("contract.pdf"))
{
    HighlightAnnotation highlight = new HighlightAnnotation
    {
        // Corner points of the region to highlight
        Points = new List<Point>
        {
            new Point(80, 730),
            new Point(240, 730),
            new Point(80, 710),
            new Point(240, 710)
        },
        BackgroundColor = 65535,
        Message = "Check this clause against the contract",
        PageNumber = 0,
        Opacity = 0.5
    };

    annotator.Add(highlight);
    annotator.Save("annotation-highlight.pdf");
}

contract.pdf is the sample file used in this example. Click here to download it.

Binary file (PDF, 132 KB)

Download full output

Read annotations back

Get returns the annotations already on a document — how you load an existing review into your own UI.

using System;
using System.Collections.Generic;
using GroupDocs.Annotation;
using GroupDocs.Annotation.Models;
using GroupDocs.Annotation.Models.AnnotationModels;

// Annotate first, so there is something to read back
using (Annotator annotator = new Annotator("contract.pdf"))
{
    annotator.Add(new AreaAnnotation
    {
        Box = new Rectangle(100, 100, 200, 100),
        Message = "Please confirm these figures",
        PageNumber = 0
    });
    annotator.Save("annotation-extract.pdf");
}

using (Annotator annotator = new Annotator("annotation-extract.pdf"))
{
    List<AnnotationBase> annotations = annotator.Get();

    Console.WriteLine("Annotations found: " + annotations.Count);

    foreach (AnnotationBase annotation in annotations)
    {
        Console.WriteLine(annotation.GetType().Name
                          + " on page " + annotation.PageNumber
                          + ": " + annotation.Message);
    }
}

contract.pdf is the sample file used in this example. Click here to download it.

Binary file (PDF, 130 KB)

Download full output

Learn more

GroupDocs.Annotation supports eighteen annotation types, threaded replies for multi-round review, updating and removing existing annotations, importing and exporting annotations as XML, page previews, and document version history.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.