Annotate documents with GroupDocs.Annotation
Leave feedback
On this page
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.
usingGroupDocs.Annotation;usingGroupDocs.Annotation.Models;usingGroupDocs.Annotation.Models.AnnotationModels;using(Annotatorannotator=newAnnotator("contract.pdf")){AreaAnnotationarea=newAreaAnnotation{Box=newRectangle(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.
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.
usingSystem.Collections.Generic;usingGroupDocs.Annotation;usingGroupDocs.Annotation.Models;usingGroupDocs.Annotation.Models.AnnotationModels;using(Annotatorannotator=newAnnotator("contract.pdf")){HighlightAnnotationhighlight=newHighlightAnnotation{// Corner points of the region to highlightPoints=newList<Point>{newPoint(80,730),newPoint(240,730),newPoint(80,710),newPoint(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.
Get returns the annotations already on a document — how you load an existing review into your own UI.
usingSystem;usingSystem.Collections.Generic;usingGroupDocs.Annotation;usingGroupDocs.Annotation.Models;usingGroupDocs.Annotation.Models.AnnotationModels;// Annotate first, so there is something to read backusing(Annotatorannotator=newAnnotator("contract.pdf")){annotator.Add(newAreaAnnotation{Box=newRectangle(100,100,200,100),Message="Please confirm these figures",PageNumber=0});annotator.Save("annotation-extract.pdf");}using(Annotatorannotator=newAnnotator("annotation-extract.pdf")){List<AnnotationBase>annotations=annotator.Get();Console.WriteLine("Annotations found: "+annotations.Count);foreach(AnnotationBaseannotationinannotations){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.
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.