How to Add Distance Annotation in PDF using C#

This article will present you with a comprehensive guide on how to add distance annotation in PDF using C#. Distance annotations are helpful in indicating the distance between two points in PDF documents, making them useful in technical drawings, construction plans, and other applications that require precise measurements. We will provide detailed instructions on setting up the annotation library and a code example to insert distance annotation to PDF in C#. The following are the essential steps for adding a distance annotation to a PDF file using the C# programming language.

Steps to Add distance Annotation in PDF using C#

  1. To incorporate distance annotations into a PDF, install GroupDocs.Annotation for .NET using the NuGet package manager
  2. Add reference of GroupDocs.Annotation namespace
  3. Create an instance of the Annotator class and pass the PDF file’s path as an argument to its constructor
  4. Create an instance of the DistanceAnnotation class and set some attributes, such as the position and page number
  5. Call the Annotator.Add method and provide the DistanceAnnotation object as an argument
  6. Call the Annotator.Save method to save final output PDF to disk

If you follow the guidelines mentioned above and install the annotation library on your computer, you can effortlessly create distance annotation in PDF using C#. These instructions can be performed on popular operating systems, such as Windows, macOS, and Linux, as long as .NET is installed. No additional software is required for incorporating distance annotations into PDF file. Additionally, the library used in the following code example is cross-platform.

Code to Add distance Annotation in PDF using C#

using GroupDocs.Annotation.Models.AnnotationModels;
using GroupDocs.Annotation.Models;
using GroupDocs.Annotation;
using System;
using System.Collections.Generic;
namespace AddDistanceAnnotationinPDFusingCSharp
{
internal class Program
{
static void Main(string[] args)
{
// Set License to avoid the limitations of Annotation library
License lic = new License();
lic.SetLicense(@"GroupDocs.Annotation.lic");
// Instantiate Annotator object by passing path of PDF
// file to its constructor
using (Annotator annotator = new Annotator("input.pdf"))
{
// Create an instance of DistanceAnnotation class
// and set some properties
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
}
}
};
// Add distance annotation to Annotator
annotator.Add(distance);
// Save the final PDF to disk
annotator.Save("result.pdf");
}
}
}
}

The previous section provided an in-depth explanation of how to add distance annotation in PDF C# along with a straightforward code example. After installing the document annotation library and modifying the input and output file paths as required, you can effortlessly integrate the code into your applications. Congratulations! You have successfully implemented a distance annotation in a PDF file using C#.

We have previously shared an article on adding ellipse annotation in PDF. If you require more information, please refer to the guide on how to add ellipse annotation in PDF using C#.

 English