Does textSearchInit API work with pdf.js express viewer?

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


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);

    });

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

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

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

Hello simar.i3r,

This is found in our Advanced Search guide, here: Advanced Search | Documentation

It is only for the Plus version.

Best regards,
Tyler