Add or Remove Annotations or Markup Word files using C#

Forget to discuss documents’ content and feedbacks in long email threads. Simply use annotations to markup documents with messages and replies. In this article, you will learn how to programmatically add and remove annotations to markup Word documents in C# with your .NET applications.

The following are the topics discussed briefly below:

.NET API to Annotate and Markup Word Files

GroupDocs.Annotation provides the .NET API to work with the annotations for your documents and images within your .NET applications. The API allows you to add, remove, and extract annotations from Word documents. Furthermore, it supports spreadsheets, presentations, images, PDF files, webpages, email messages, Visio drawings. Some AutoCAD drawings and digital imaging formats like DICOM are also on the list. For the complete list of supported document formats for annotation, you can visit the documentation.

Download the 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 Word in C#

Let’s add some of the different kinds of annotations to the Word documents. There are many different types of annotation, so we will be covering only a few in this article.

Add Annotations to DOC DOCX using GroupDocs API

There are some of the supported annotation types, you may learn about each annotation individually.

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

Add Arrow Annotation to Word using C#

The following are the steps to add arrow annotation to a Word document in C#.

Add Arrow Annotation Programmatically in Java and .NET
  • Load the document using the Annotator class.
  • Initialize arrow annotation with ArrowAnnotation class.
  • Adjust the position, size, page number of the arrow annotation.
  • Add the created arrow annotation using Add method.
  • Save the annotated Word document to the path using the Save method.

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

Insert Rectangle or Area Annotation to Word using C#

Customizations can be done for any annotation while adding it to the document. The following are the steps to add rectangle or area annotation to a DOC/DOCX document with some customizations. It is very similar to adding Arrow annotations but uses AreaAnnotation class this time.

  • Load the DOC/DOCX document using the Annotator class.
  • Initialize rectangle annotation using AreaAnnotation class.
  • Adjust the position, size, and color of the rectangle.
  • Set other properties like page number, background, opacity, style, pen width, messages, and time.
  • Add the created rectangle annotation to the Annotator.
  • Save the annotated file to the path using the Save method.
Add Rectangle or Area Annotation Programmatically in .NET and Java

The following code sample shows how to add rectangle/area annotation to a Word document using C#.

Add Oval or Ellipse Annotation to Word using C#

The following are the steps to add oval annotation or ellipse annotation to a document in C#.

Add Ellipses or Oval Annotation Programatically in C# .NET and Java
  • Load the DOC/DOCX document using the Annotator class.
  • Initialize ellipse annotation using EllipseAnnotation class.
  • Set the position and size of the initialized ellipse annotation.
  • Add the created ellipse annotation to the Annotator object.
  • Provide the path and save the annotated Word file using the Save method.

The following code sample shows how to add oval or ellipse annotation to a Word document using C#.

Insert Distance Annotation to Word using C#

Similarly, you can add the distance annotation to mark the distance between two points. The following are the steps to add distance annotation to the document.

Add Distance Annotation Programmatically in C# .NET and Java
  • After loading the Word document, initialize distance annotation using DistanceAnnotation class.
  • Set the appearance of the annotation.
  • Add the distance annotation to the Annotator object.
  • Save the annotated Word files at the given location by specifying the path.

The following code sample shows how to add distance annotation to a DOC/DOCX document using C#.

Complete Code

To sum up, here is the complete code with the output showing all the added annotations and messages with replies. The following C# code below adds, arrow, rectangle, ellipse, distance annotations, messages, and replies to a Word file.

Remove Annotations from Word DOC/DOCX files using C#

Annotations from the documents can be removed easily. There are many options to remove the annotations from a Word document. You can remove all the annotations at once. Additionally, you can provide the indexes to remove the specific annotations. For more options, visit the documentation article.

The following are the steps to remove all the annotations from a Word file.

  • Load the document.
  • Initialize saving options using SaveOptions class.
  • Set the annotation types to None.
  • Save the Word file. It will have no annotation in it.

The following code shows how to remove annotations from a Word file using C#.

Conclusion

In short, you have learned how to add annotations to Word documents within .NET applications using C#. Specifically, we added arrow, ellipse, area, and distance annotations to the Word DOC/DOCX file. Further, you have also seen how to remove all the annotations from any Word file. Now, you can think to build your own document annotator .NET application.

Learn more about GroupDocs.Annotation for .NET from the documentation and the GitHub repository. For further queries, contact the support on the forum.

See Also