Is it possible to set default search options for all searches?

Hi, I know that I can trigger a “searchTextFull” manually and pass searchOptions (https://www.pdftron.com/api/web/WebViewerInstance.html → searchTextFull), but if I type in the default input text field provided in the UI, an “automatic” search is triggered with default options. In my case I would like to have the “wildcard” option set to true for all searches (its default value is false). Is there a way to set this globally, maybe in the “onDocumentLoaded” event or something? Thanx in advance.

Hi Mirko,

Thanks for contacting us regarding WebViewer!

Unfortunately I don’t think we have APIs to set default options right now, but I was able to find a workaround.

WebViewer({
  initialDoc: hashFile,
  path: '/lib',
}, document.getElementById('viewer')).then(instance => {
  instance.docViewer.on('documentLoaded', () => {
    instance.searchTextFull('', {
      wildcard: true,
    });
    instance.closeElements(['searchPanel', 'searchOverlay']);
  })
});

The code above will set the wildcard to true and then perform a dummy search. Since searchTextFull will open the search panel, we need to close it immediately.

The workaround isn’t pretty and I think it makes sense to have an API for setting default search options. I will put it into the backlog. Let me know how the code works for you and if you have any other questions.

Best Regards,
Zhijie Zhang
Software Developer
PDFTron Systems Inc.

Hi Zhijie and thanx for your reply.
Actually what you suggest me is what I have already done, I take an input query from a text field, then I open a pdf and in the “documentLoaded” event I start a “searchTextFull” with the given term and the wildcard option, as you set it. The problem is, if I afterwards edit the search input field of the webViewer directly, an automatic search within the pdf is triggered (which is ok), but without the “wildcard” option. That’s the point of my question, I wanted to set this option globally so that every search would consider wildcards. But since you told me, that this is not present in the API, I think as a workaround I will hide the default search input field of the webViewer via CSS and replace it with a custom input field, to which I will then listen to “change” events and perform the “searchTextFull” via code with the wildcard parameter.
Best regards
Mirko Lugano

Hi Mirko,

Just to clarify that you’ve found a workaround to resolve the issue?

Regarding “if I afterwards edit the search input field of the webViewer directly, an automatic search within the pdf is triggered (which is ok), but without the “wildcard” option.”. I’m having some trouble reproducing this issue. After I called searchTextFull with the wildcard option, I can still use * in the search input field to perform a single search. Just to confirm that the search input field you are referring to is the input that pops up when you click the glass icon in the toolbar?

Thanks,
Zhijie Zhang
Software Developer
PDFTron Systems Inc.

Hi Zhijie
very strange. Yes, it’s the same input field, although I have made a few changes in the UI and made the search panel always show, but the input field itself it’s the same (jquery selector: $(’.input-wrapper > input’)). Anyway I have substituted the input field with another custom input field and hidden the original one, so that I now trigget always the searchTextFull by code and it works perfectly. Thanx anyway for your help.
Best regards
Mirko