While reviewing or to attract viewer to an important content, you may need to highlight some part of the document. As a developer, you can automate this feature by using highlight annotations within your applications. In this article, you will learn how to highlight text and any area in PDF files using C#.

The following topics are covered below:

Highlight Text in PDF - Programmatically

.NET API to Highlight in PDF

GroupDocs.Annotation provides .NET API that allows manipulating annotations and their automation in documents within .NET applications. I am using this API to highlight text in the PDF file in the example of this article.

You can download the DLLs or MSI installer from the downloads section or install the API in your .NET application via NuGet.

PM> Install-Package GroupDocs.Annotation

Highlight in PDF using C#

The following are the steps to highlight text or any area in PDF from your .NET application.

  • Load the source PDF document using Annotator class.
  • Create the HighlightAnnotation object.
  • Define the highlight properties like the color, opacity, page number, and points.
  • Add the defined highlighting to the loaded PDF document using Add method.
  • Save the annotated PDF using Save method.

Note: You may change the highlight color, opacity, and other properties.

The following code sample shows how to highlight the text in PDF programmatically using C#.

The following is the output of the above code.

Highlight Text in PDF - Programmatically

Get a Free API License

You can get a free temporary license in order to use the API without the evaluation limitations.

Conclusion

To sum up, we have learned how to add highlight annotation in PDF files programmatically using C#. Additionally, we can change the highlight color, opacity, and other properties. Many different types of annotations can be added in a similar way using the same API.

To learn about the API, visit the documentation. For queries, contact us via the forum.

See Also