Add search text annotation

On this page

Search text annotation searches for specific text and highlight it as shown in the picture below:

You can specify the following properties of the SearchTextAnnotation class:

  • BackgroundColor defines the area background color
  • Text defines the text to be found. If the document does not contain the specific text, nothing will be highlighted
  • FontColor defines the color of the text
  • FontFamily defines the name of text font
  • FontSize defines the text font size

To add a search text annotation, follow these steps: 

  1. Instantiate the Annotator class. Specify the input document path or stream.
  2. Instantiate the SearchText class. Specify the appropriate properties (position, page number, etc).
  3. Call the Add method. Specify the SearchTextAnnotation class.
  4. Call the Save method. Specify the output document path or stream.

The following code snippet shows demonstrates how to add SearchTextAnnotation to the document:

//Add search text annotation to the document from local disk
try(final Annotator annotator = new Annotator("input.pdf")){
	SearchTextFragment searchTextFragment = new SearchTextFragment();
	searchTextFragment.setText("Welcome to GroupDocs");//If the document does not contain this text, nothing will be highlighted

On this page