This easy‑to‑follow tutorial shows how to search for text and highlight in PDF using C#, walking you through loading a PDF document, locating specific text, creating highlight annotations in various colors and shapes, and applying those annotations to emphasize the text—all without installing any third‑party software. It’s the perfect guide for developers who want to improve PDF readability or draw attention to important information using native C# tools and techniques.
Steps to Search Text and Highlight in PDF using C#
- Configure Conholdate.Total for .NET library from the NuGet package manager to highlight any text in PDF
- Load the input PDF file with the Document class object to search some text and highlight it
- Search text in the PDF to highlight
- Create HighlightAnnotation while specifying the color and shape
- Apply the highlight annotation to the searched text
- Save the output PDF file with highlighted text
These instructions detail the straightforward method to highlight text in PDF using C#. The process begins with searching for a particular string within the document. Once located, you can then proceed to highlight this text. Additionally, there’s the option to select the color for highlighting, such as yellow, red, or any other preferred color, and to choose the shape of the highlight to meet your specific needs. This flexibility allows for a customized approach to emphasizing key portions of text in your PDF documents, enhancing both the visual appeal and the functional utility of the highlighted content.
Code to Highlight Words in PDF using C#
This snippet demonstrates how to highlight text in a PDF using C#. First, the TextFragmentAbsorber class locates the target string on the chosen page. Next, a HighlightAnnotation is created to define the highlight’s properties—such as color and opacity. After setting these attributes, the annotation is applied to the found text, rendering the highlight exactly as specified. Finally, the document is saved, leaving the selected text clearly highlighted for easy identification and reference.
In this tutorial we demonstrated how to highlight specific text within a PDF using C#. If you’d like to take the next step and read PDF content programmatically, explore our guide on how to Read PDF in C#.