This simple guide discusses how to search text and highlight in PDF using C#. It guides loading a PDF, searching some text in PDF, creating highlight annotations with color and shape, and applying different highlight annotations to some text. You can highlight pdf document using C# without installing any third-party tool.
Steps to Search Text and Highlight in PDF using C#
- Configure Aspose.PDF 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 steps elaborate the simple process to highlight text in PDF using C#. You only need to search for a specific string in the document and then highlight it. Moreover, you can choose the color to highlight the text like yellow, red, or any other color along with the shape as per your requirements.
Code to Highlight Words in PDF using C#
This code answers the question of how to highlight in PDF using C#. TextFragmentAbsorber class is used to search a string on a particular page in the PDF. HighlightAnnotation class is used to define the characteristics of the highlighter to be used. In the end, we add the defined annotation to highlight text in PDF before saving it on the disk.
This tutorial has explained about highlighting specific text in a PDF file. However, if you are interested in reading a PDF file programmatically, head to the article on how to Read PDF in C#.