Searching for any word in a phrase

Skip to first unread message

Matt Parizeau

May 30, 2018, 3:52:42 PM5/30/18
to PDFTron WebViewer

Is it possible to search for any word in a phrase inside a document instead of just the whole phrase? For example if I search "pdftron webviewer" I want it to match "pdftron", "webviewer" and "pdftron webviewer".


You can take advantage of the regex search mode to construct a regular expression that does what you want. For example you could have a regular expression like /pdftron webviewer|pdftron|webviewer/ to search for either the whole phrase or the individual words. You could do this by adding the following code to your config file which adjusts the default call to textSearchInit and creates that regular expression:

var textSearchInit = CoreControls.DocumentViewer.prototype.textSearchInit;
CoreControls.DocumentViewer.prototype.textSearchInit = function(pattern, mode, fullSearch, onSearchCallback) {
var anyWordPattern = pattern + '|' + pattern.split(' ').join('|');
var regexMode = mode |= readerControl.docViewer.SearchMode.e_regex;

.apply(this, [anyWordPattern, regexMode, fullSearch, onSearchCallback]);

Reply all
Reply to author
0 new messages