No more long discussions within long email threads about the content of the document(s). You can use annotations to markup documents with personalized messages and their replies. This article discusses how to programmatically annotate PDF files to markup documents using C#. Additionally, we will also discuss how to remove annotations from PDF files.

The following topics are discussed briefly below:

.NET API to Annotate PDF Files

GroupDocs.Annotation has its .NET API to work with the annotations within the documents and images. It allows you to add, remove, and extract annotations from PDF & Word documents, spreadsheets, and presentations. Furthermore, it supports images, webpages, email messages, Visio drawings, and much more. You can have a look at the documentation for the complete list of supported document formats for annotation.

Download its DLLs or MSI installer from the downloads section or install the API in your .NET application via NuGet. You may also use the following command from the Package Manager.

PM> Install-Package GroupDocs.Annotation

Add Annotations to PDF using C#

There are many different types of annotations that are available to add within the documents, however, we will discuss only a few in this article.

Added Annotations to PDF

The following are some of the supported annotations. You may learn about each annotation individually.

  • Area / Rectangle annotation
  • Arrow
  • Distance
  • Ellipse
  • Highlight
  • Link
  • Point
  • Polyline – Replacement
  • Resource Redaction
  • Strikeout
  • Text Field
  • Text Redaction
  • Underline
  • Watermark

Add Arrow Annotation to PDF using C#

The following are the steps for how to add arrow annotations to PDF documents in C#.

Add Arrow Annotation Programmatically in Java and C# .NET
  • Load the PDF document using the Annotator class.
  • Initialize the Arrow Annotation.
  • Define the position, size, page number of the arrow annotation.
  • Add the defined arrow annotation using the Add method.
  • Save the annotated document using the appropriate Save() method.

The following C# code sample shows how to add an arrow annotation to a PDF document.

Insert Rectangle or Area Annotation to PDF using C#

The following are the steps to add a rectangle or area annotation to a PDF document with some customizations. It is very similar to adding Arrow annotations but uses AreaAnnotation.

  • Load the PDF document using the Annotator class.
  • Initialize the rectangle annotation using AreaAnnotation class.
  • Specify the position, size, and color of the rectangle.
  • You can also set other properties like page number, background, opacity, style, pen width, messages, and time.
  • Add the defined rectangle annotation to the Annotator.
  • Lastly, save the annotated file using the Save() method.
Add Rectangle or Area Annotation Programmatically in C# .NET and Java

The following code sample adds rectangle/area annotation to a PDF document using C#.

Add Oval or Ellipse Annotation to PDF using C#

Likewise, let’s add the ellipse/oval annotation. The following steps show how an oval annotation or ellipse annotation can be added to a PDF file using C#.

Add Ellipses or Oval Annotation Programatically in C# .NET and Java
  • Load the PDF file using the Annotator class.
  • Initialize the Ellipse Annotation.
  • Set the position, size, and other properties of the initialized annotation.
  • Add the created ellipse annotation to the Annotator object.
  • Use the Save() method to save the annotated PDF file.

The following C# code example adds an oval/ellipse annotation to a PDF document.

Insert Distance Annotation to PDF using C#

You can use distance annotation to point out the distance between two objects. The following are the steps that add distance annotation to the PDF document using C#.

Add Distance Annotation Programmatically in C# .NET and Java
  • After loading the PDF document using Annotator class, initialize the distance annotation using DistanceAnnotation class.
  • Set the appearance, line color, thickness, style, etc.
  • Add the distance annotation to the Annotator.
  • Save the PDF file with the annotation using the appropriate Save() method.

The following code snippet shows how to add the distance annotation within the PDF using C#.

Remove Annotations from PDF files using C#

There are different ways to remove annotations from PDF documents. Either, you can remove all the annotations at once, or you can provide IDs, indexes to remove the selective ones. We discussed the different ways of removing annotations in the separate article. However, here are the steps to remove all the annotations from a PDF file.

  • Load the document.
  • Initialize the Save Options.
  • Set the annotation types to None.
  • Save the annotation free PDF file using the Save() method.

The following C# code shows how to remove annotations from PDF files.

Conclusion

To conclude, you learned how to add different annotations to PDF documents within the .NET applications using C#. More precisely, we added arrow, ellipse, area, and distance annotations. Further, you have also seen one of the ways to remove all the annotations from any PDF file.

You can think to build your own document annotator .NET application. For more about the GroupDocs.Annotation for .NET, visit the documentation and the GitHub repository. For further queries, contact the support on the forum.

See Also