# Multi search with different color to higlight

**URL:** <https://pdfjs.community/t/multi-search-with-different-color-to-higlight/3533>\
**Category:** Technical Support\
**Created:** [November 28, 2024, 10:02am UTC](https://pdfjs.community/t/multi-search-with-different-color-to-higlight/3533 "2024-11-28T10:02:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![prajneshu.khandavall](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@prajneshu.khandavall](https://pdfjs.community/u/prajneshu.khandavall)\
**Post date:** [November 28, 2024, 10:02am UTC](https://pdfjs.community/t/multi-search-with-different-color-to-higlight/3533/1 "2024-11-28T10:02:59Z")

</div>

**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

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [November 28, 2024, 4:26pm UTC](https://pdfjs.community/t/multi-search-with-different-color-to-higlight/3533/3 "2024-11-28T16:26:29Z")

</div>

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:

> **[Advanced Search | Documentation](https://pdfjs.express/documentation/search/advanced-search)**

Best regards,  
Kevin

---

<div class="post-metadata">

**Author:** ![prajneshu.khandavall](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@prajneshu.khandavall](https://pdfjs.community/u/prajneshu.khandavall)\
**Post date:** [November 29, 2024, 5:19am UTC](https://pdfjs.community/t/multi-search-with-different-color-to-higlight/3533/4 "2024-11-29T05:19:14Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [November 29, 2024, 5:07pm UTC](https://pdfjs.community/t/multi-search-with-different-color-to-higlight/3533/5 "2024-11-29T17:07:20Z")

</div>

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:

> **[Customize Display Authors for Annotations | PDF.js Express](https://pdfjs.express/documentation/annotation/display-authors#map-a-userid-to-a-display-author)**

best regards,  
Kevin
