Multi search with different color to higlight

Which product are you using?
PDF.js Express Plus

PDF.js Express Version
8.7.2

Detailed description of issue
We have been using textSearchInit api to achieve multi search functionality and it has been working. we want to apply custom color the each term results.

Expected behaviour
Each term results highlight color should be unique .

Does your issue happen with every document, or just one?
Yes

Link to document
NA

Code snippet
NA

Hi there,

You can do this via the following:

  1. Perform the search using textSearchInit without the highlight mode enabled.
  2. In the onResult callback, check the result.resultStr to determine which search term was found.
  3. Create a new TextHighlightAnnotation for each search term found and set the StrokeColor property to the desired color.
  4. Add the annotation to the document using the AnnotationManager.

Please see this guide for the usage of textSearchInit api:

Best regards,
Kevin

Hi @kkim ,

Thanks for the quick reply. we tried the above scenario it worked but after clearing search results they are still holding highlights in the document . how to delete only search highlighted results?(need to keep existing annotations in the document which we draw using annotation tab)

Hi there,

One way to distinguish the annotations created from the search result would be to use the setCustomData property as they are created. Then delete all annotations that have this property when needed.
An example usage of this API is available here:

best regards,
Kevin