# Does textSearchInit API work with pdf.js express viewer?

**URL:** <https://pdfjs.community/t/does-textsearchinit-api-work-with-pdf-js-express-viewer/2938>\
**Category:** Technical Support\
**Created:** [November 5, 2023, 6:55pm UTC](https://pdfjs.community/t/does-textsearchinit-api-work-with-pdf-js-express-viewer/2938 "2023-11-05T18:55:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![simar.i3r](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/simar.i3r/32/1601_2.png) [@simar.i3r](https://pdfjs.community/u/simar.i3r)\
**Post date:** [November 5, 2023, 6:55pm UTC](https://pdfjs.community/t/does-textsearchinit-api-work-with-pdf-js-express-viewer/2938/1 "2023-11-05T18:55:05Z")

</div>

**Which product are you using?**  
PDF.js Express Viewer

**PDF.js Express Version**  
8.7.2

**Detailed description of issue**  
I’m using textSearchInit API to search for something in my document but I don’t see any search done in the pdf viewer or any output on the console. Is it because annotations are not supported in the pdf js express viewer?

**Expected behaviour**  
The search should happen and relevant string should be highlighted in the viewer

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

**Code snippet**

```javascript

WebViewer({
    path: '/static/assets/pdfjs-express-viewer',
    licenseKey: '',
    initialDoc: pdfpath,
    enableAnnotations: true
    // initialDoc: 'https://pdftron.s3.amazonaws.com/downloads/pl/webviewer-demo.pdf',
}, document.getElementById('viewer'))
    .then(instance => {
        // now you can access APIs through the WebViewer instance
        const {Core, UI} = instance;

        UI.disableElements(['rightPanel']);
        UI.disableElements(['leftPanel', 'leftPanelButton']);
        pdfjs_instance = instance
        pdfjs_docviewer = Core.documentViewer

        // adding an event listener for when a document is loaded
        Core.documentViewer.addEventListener('documentLoaded', () => {
            console.log('Document loaded');
        });

      const {
    documentViewer,
    Core2,
    annotationManager,
    Annotations
  } = instance.Core;

    // Set search modes. See the API reference for more information
    const searchMode = Core.Search.Mode.PAGE_STOP | Core.Search.Mode.HIGHLIGHT;

    const searchOptions = {
      fullSearch: true, // search the full document
      onResult: (result) => {
          console.log('Search done')
        if (result.resultCode === Core.Search.ResultCode.FOUND) {

          if (!result.quads.length) return;

          console.log(result);

          const textQuad = result.quads[0].getPoints();
          const annot = new Annotations.TextHighlightAnnotation();

          annot.X = textQuad.x1;
          annot.Width = textQuad.x2 - textQuad.x1;
          annot.PageNumber = result.pageNum;
          annot.Y = textQuad.y3;
          annot.Height = textQuad.y1 - textQuad.y3;

          annot.FillColor = new Annotations.Color(0, 0, 255, 0.5);
          annot.StrokeColor = new Annotations.Color(0, 0, 255, 0.5);

          annot.Quads = [textQuad];

          annotationManager.addAnnotation(annot);
          annotationManager.drawAnnotationsFromList([annot])
        }
      }
    }

    // start the search
  documentViewer.textSearchInit('Strata', searchMode, searchOptions);

    });

```

---

<div class="post-metadata">

**Author:** ![ejohnson](https://avatars.discourse-cdn.com/v4/letter/e/a3d4f5/32.png) [@ejohnson](https://pdfjs.community/u/ejohnson)\
**Post date:** [November 6, 2023, 5:47pm UTC](https://pdfjs.community/t/does-textsearchinit-api-work-with-pdf-js-express-viewer/2938/2 "2023-11-06T17:47:10Z")

</div>

Thank you for posting your question to our forum. We will provide you with an update as soon as possible.

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [November 6, 2023, 11:28pm UTC](https://pdfjs.community/t/does-textsearchinit-api-work-with-pdf-js-express-viewer/2938/3 "2023-11-06T23:28:11Z")

</div>

Hello simar.i3r,

The textSearchInit API searches the text on the document, not the annotations. Can you provide a code snippet and a test file to try out?

Best regards,  
Tyler

---

<div class="post-metadata">

**Author:** ![simar.i3r](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/simar.i3r/32/1601_2.png) [@simar.i3r](https://pdfjs.community/u/simar.i3r)\
**Post date:** [November 11, 2023, 9:14am UTC](https://pdfjs.community/t/does-textsearchinit-api-work-with-pdf-js-express-viewer/2938/4 "2023-11-11T09:14:16Z")

</div>

My question is whether it is supported in pdfjs express viewer or only with pdfjs express plus?

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [November 15, 2023, 10:46pm UTC](https://pdfjs.community/t/does-textsearchinit-api-work-with-pdf-js-express-viewer/2938/5 "2023-11-15T22:46:49Z")

</div>

Hello simar.i3r,

This is found in our Advanced Search guide, here: [Advanced Search | Documentation](https://pdfjs.express/documentation/search/advanced-search)

It is only for the Plus version.

Best regards,  
Tyler
