Add distance annotation

On this page

Distance annotation shows a distance between objects in a document as shown in the picture below: 

You can set the following properties of the DistanceAnnotation class:

  • Box defines annotation position on a page
  • Opacity allows you to set the annotation opacity
  • PenColor defines the annotation color
  • PenStyle defines the annotation line style (solid, dash, dot etc.)
  • PenWidth defines the line width in pixels

To add a distance annotation to document, follow these steps:  

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

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

//Add distance annotation to the document from local disk
using (Annotator annotator = new Annotator("input.pdf"))
{
	DistanceAnnotation distance = new DistanceAnnotation
    {
        Box = new Rectangle(200, 150, 200, 30),
        CreatedOn = DateTime.Now,
        Message = "This is distance annotation",
        Opacity = 0.7,
        PageNumber = 0,
        PenColor = 65535,
        PenStyle = PenStyle.Dot,
        PenWidth = 3,
        Replies = new List<Reply>
        {
        	new Reply
            {
            	Comment = "First comment",
                RepliedOn = DateTime.Now
            },
            new Reply
            {
            	Comment = "Second comment",
                RepliedOn = DateTime.Now
            }
        }
    };
    annotator.Add(distance);
    annotator.Save("result.pdf");
}

On this page