# PDF.JS Express only search first ocurrence once and no more

**URL:** <https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187>\
**Category:** Bug Reports\
**Tags:** pdfjs-express\
**Created:** [November 21, 2022, 3:02pm UTC](https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187 "2022-11-21T15:02:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ti11](https://avatars.discourse-cdn.com/v4/letter/t/ce7236/32.png) [@ti11](https://pdfjs.community/u/ti11)\
**Post date:** [November 21, 2022, 3:02pm UTC](https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187/1 "2022-11-21T15:02:20Z")

</div>

Hi guys,

I’m using pdf.js-express 8.7.0. We use too much search and I founded out a behavior always I search.

When I search “energia” in my PDF opened with PDF.JS Express, it returns correct search and brought me first ocurrence.

After, somethimes I clear fieldtext and search again by “energia” in the same work, it doesn’t return the same result, doesn’t brought me first ocurrence. See image below:

![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/5/59d495b3da5f3175134a29e93a5788afc7133f35.png)

Someone can help me?

Thanks too much

---

<div class="post-metadata">

**Author:** ![ti11](https://avatars.discourse-cdn.com/v4/letter/t/ce7236/32.png) [@ti11](https://pdfjs.community/u/ti11)\
**Post date:** [November 21, 2022, 3:03pm UTC](https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187/3 "2022-11-21T15:03:02Z")

</div>

Below, is the result of first search:

![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/1/143908fb23d7955cca087dd065c8e3d61690f0b9.png)

---

<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 21, 2022, 8:26pm UTC](https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187/4 "2022-11-21T20:26:16Z")

</div>

Hi ti11,

Thank you for contacting pdf.js express forums,

Does the search result show the same number of occurrence?  
Does this issue happen for only a specific file? If so, can you share a file that reproduces the issue?

I was unable to reproduce on the demo site (8.7): [PDF.js Viewer Demo | PDF.js Express](https://pdfjs.express/demo)  
Do you have any custom code for the search functionality?

Thank you in advance.

Best regards,  
Kevin Kim

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![ti11](https://avatars.discourse-cdn.com/v4/letter/t/ce7236/32.png) [@ti11](https://pdfjs.community/u/ti11)\
**Post date:** [November 22, 2022, 3:22pm UTC](https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187/5 "2022-11-22T15:22:30Z")

</div>

Hi Kevin Kim,

No, when I test the search, all results is not the same. This problem ocurrs always my documents and there isn’t any custom search functionality.

I will include pdf example here. I cannot reproduce same problem with this link [PDF.js Viewer Demo | PDF.js Express](https://pdfjs.express/demo) that you sent.

My version is the same, 8.7.0.

File example:  
[example.pdf](https://pdfjs.community/uploads/short-url/cpDFZg59VMSnCuxJsGNm9EnkSC7.pdf) (7.1 MB)

To reproduce this error, search by “equipamentos” (there is a ocurrence in first page). Immediately, erase last letter S and put again.

After this, no words in first page will be found.

---

<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 22, 2022, 4:50pm UTC](https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187/6 "2022-11-22T16:50:25Z")

</div>

Hi there,

Thank you for your response,

When I uploaded the document on our latest package (8.7) I was unable to reproduce the issue.  
Video attached: [40760.mov](https://pdftron-my.sharepoint.com/:v:/p/kkim/EcdyNaXRJbNOqa4osh0tZ0QBhkNKxyV4winC_ti3XVb3xw?e=cdOIl5)  
However there were some console errors from this pdf. Does this happen with any other pdf without issues?

Another option you could try is use redrawAnnotation right after the search event using a listener:  
[https://pdfjs.express/api/Core.AnnotationManager.html#redrawAnnotation\_\_anchor](https://pdfjs.express/api/Core.AnnotationManager.html#redrawAnnotation__anchor)  
[https://pdfjs.express/api/UI.html#.addSearchListener\_\_anchor](https://pdfjs.express/api/UI.html#.addSearchListener__anchor)

Best regards,  
Kevin Kim

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![ti11](https://avatars.discourse-cdn.com/v4/letter/t/ce7236/32.png) [@ti11](https://pdfjs.community/u/ti11)\
**Post date:** [November 22, 2022, 5:28pm UTC](https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187/7 "2022-11-22T17:28:02Z")

</div>

Hi,

I record the error. See error in link below:

[![](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/7/74e163f9fc8ed2c845e51364e2a6b9c826e2eed1.jpeg "Exemplo Pesquisa") ](https://www.youtube.com/watch?v=ERc5HM6mbnw)

You need to type any letter.

---

<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 22, 2022, 10:19pm UTC](https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187/8 "2022-11-22T22:19:30Z")

</div>

Hi there,

Thank you for the video,

I was able to reproduce it by removing the last letter before the search completes (spinning wheel). When the search was in progress, if you open the console there are the above mentioned warnings, and if we wait for it to complete, the search seems less to error out less.

We’ve added the issue to our backlog to be worked on in the future. We don’t have a timeline for when it will be fixed but if it does get fixed we’ll let you know when it’s available in an experimental build to test out and the estimated official release date. If you have a desired timeline for having this issue fixed please let us know and we’ll do our best to work with you on how this can fit into the release schedule.

Best regards,  
Kevin Kim

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![ti11](https://avatars.discourse-cdn.com/v4/letter/t/ce7236/32.png) [@ti11](https://pdfjs.community/u/ti11)\
**Post date:** [November 23, 2022, 1:38pm UTC](https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187/9 "2022-11-23T13:38:14Z")

</div>

Hi Kevin Kim,

We are a few days of a new release and we found this error.

If we cannot solve this error, we will abort and change pdf.js express. I posted here to try understand if this is a bug or just error.

Can you help us?

---

<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 24, 2022, 9:13pm UTC](https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187/10 "2022-11-24T21:13:44Z")

</div>

Hi there,

Thank you for your patience, this could be related to the warnings you saw on the console that occurred for some documents.

Could you please try this build [https://pdftron.s3.amazonaws.com/custom/ID-zJWLuhTffd3c/WebViewer/PDFJSExpress-8.7.0-40760.zip](https://pdftron.s3.amazonaws.com/custom/ID-zJWLuhTffd3c/WebViewer/PDFJSExpress-8.7.0-40760.zip) and let me know if that solves your issues.

Best regards,  
Kevin Kim

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![ti11](https://avatars.discourse-cdn.com/v4/letter/t/ce7236/32.png) [@ti11](https://pdfjs.community/u/ti11)\
**Post date:** [November 27, 2022, 2:52pm UTC](https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187/11 "2022-11-27T14:52:17Z")

</div>

Hello Kim, thank you very much for your attention.

I believe the problem is not the alerts in the console. During the tests, I analyzed that when we wait for the search to complete and we redo the test by deleting the last letter, the error does not happen; that is, the error only occurs when the search is carried out when there is already a search in the process.

---

<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, 2022, 3:32pm UTC](https://pdfjs.community/t/pdf-js-express-only-search-first-ocurrence-once-and-no-more/2187/12 "2022-11-28T15:32:13Z")

</div>

Hi there,

Were you able to try out the build above if that fixes the issue?

After the first load of the pdf, the first search seems to trigger console warnings. A temporary workaround would be to add a searchListener for when the search completes:  
[https://pdfjs.express/api/UI.html#.searchListener\_\_anchor](https://pdfjs.express/api/UI.html#.searchListener__anchor)

Best regards,  
Kevin Kim

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)
