Add highlight annotation

On this page

Highlight annotation highlights and comments selected text as shown in the picture below:

You can set the following properties of the HighlightAnnotation class:

  • BackgroundColor defines the annotation background color
  • FontColor defines the color of annotation text
  • Opacity - allows you to set the annotation opacity
  • Points defines the annotation positions as an array of points

To add a highlight annotation, follow these steps:

  1. Instantiate the Annotator class. Specify the input document path or stream.
  2. Instantiate HighlightAnnotation class. Specify the appropriate properties (position, page number, etc).
  3. Call the Add method. Specify the HighlightAnnotation class.
  4. Call the Save method. Specify the output document path or stream.

The following code snippet shows how to add HighlightAnnotation to the document:

//Add highlight annotation to the document from local disk
using (Annotator annotator = new Annotator("input.pdf"))
{
	HighlightAnnotation highlight = new HighlightAnnotation
    {
    	BackgroundColor = 65535,
        CreatedOn = DateTime.Now,
        FontColor = 0,
        Message = "This is highlight annotation",
        Opacity = 0.5,
        PageNumber = 0,
        Points = new List<Point>
        {
        	new Point(80, 730), new Point(240, 730), new Point(80, 650), new Point(240, 650)
        },
        Replies = new List<Reply>
        {
        	new Reply
            {
            	Comment = "First comment",
                RepliedOn = DateTime.Now
            },
            new Reply
            {
            	Comment = "Second comment",
                RepliedOn = DateTime.Now
            }
        }
    };
    annotator.Add(highlight);
    annotator.Save("result.pdf");
} 

On this page