Add search text annotation

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Annotation MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-annotation -- dnx GroupDocs.Annotation.Mcp --yes
Folders, licensing and more →

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
	searchTextFragment.setFontSize(10.);
	searchTextFragment.setFontFamily("Calibri");
	searchTextFragment.setFontColor(65535);
	searchTextFragment.setBackgroundColor(16761035);
	annotator.add(searchTextFragment);
	annotator.save("result_add_search_text.pdf");
}

On this page