Multi search with regex

Which product are you using?
PDF.js Express Plus

PDF.js Express Version
6.3.4
Detailed description of issue
we have been looking for a viewer with multi search capability along regex/wild characters. i went through the documentation but couldn’t be able to find it. is there any way to achieve this?

Expected behaviour
If i provide multiple search terms those need to be highlighted in the viewer along with existing features

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

Link to document
NA

Code snippet
NA

Hi there,

You could use the textSearchInit API along with keeping previous results using something like this:

const results = [];

const performSearch = (searchTerm) => {
  return new Promise(resolve => {
    const mode = Core.Search.Mode.PAGE_STOP | Core.Search.Mode.HIGHLIGHT | Core.Search.Mode.AMBIENT_STRING | Core.Search.Mode.REGEX;
    const searchOptions = {
      fullSearch: true,
      onResult: (result) => {
        results.push(result);
        documentViewer.displayAdditionalSearchResult(result);
      },
      onDocumentEnd: () => {
        resolve();
      }
    };
    documentViewer.textSearchInit(searchTerm, mode, searchOptions);

    documentViewer.displayAdditionalSearchResults(results);
  });
};

  await performSearch(searchTerm1);
  await performSearch(searchTerm2);
  await performSearch(searchTerm3);

This will keep highlight on multiple results:

Best regards,
Kevin Kim

Hi Kevin thanks for the quick reply .it’s perfectly working. is there a way to show all the search terms in the ui to the end user?.

Glad that worked for you,

There is no simple api to show the search terms, but you could grab the DOM input element in the search panel and manually fit them in during the search:

Best regards,
Kevin Kim

Thank you so much. will try it.

Hi @kkim one more question like if we are doing search from the ui input then existing search results are disappearing. is there anyway to keep previous results as well with the ui search?

Hi there,

Unfortunately performing a search on the UI would mean cancelling and performing a new search. By design it will stop the current search and start a new search.