Determine if the search query constitutes a "whole word", by comparing the first/last character type with the preceding/following character type.
Helper for multi-term search that fills the matchesWithLength
array
and handles cases where one search term includes another search term (for
example, "tamed tame" or "this is"). It looks for intersecting terms in
the matches
and keeps elements with a longer match length.
Cancel search task.
// Open the document, find the text 'wildlife' and highlight the first result:
async function loadPdfViewer(selector) {
var viewer = new GcPdfViewer(selector, { restoreViewStateOnLoad: false });
viewer.addDefaultPanels();
var afterOpenPromise = new Promise((resolve)=>{ viewer.onAfterOpen.register(()=>{ resolve(); }); });
await viewer.open('wetlands.pdf');
await afterOpenPromise;
var findOptions = { Text: 'wildlife' };
var searchIterator = await viewer.searcher.search(findOptions);
var searchResult = await searchIterator.next();
viewer.searcher.cancel();
viewer.searcher.highlight(searchResult.value);
}
loadPdfViewer('#root');
Navigates to a page containing the result and highlights found text.
// Open the document, find the text 'wildlife' and highlight the first result:
async function loadPdfViewer(selector) {
var viewer = new GcPdfViewer(selector, { restoreViewStateOnLoad: false });
viewer.addDefaultPanels();
var afterOpenPromise = new Promise((resolve)=>{ viewer.onAfterOpen.register(()=>{ resolve(); }); });
await viewer.open('wetlands.pdf');
await afterOpenPromise;
var findOptions = { Text: 'wildlife' };
var searchIterator = await viewer.searcher.search(findOptions);
var searchResult = await searchIterator.next();
viewer.searcher.cancel();
viewer.searcher.highlight(searchResult.value);
}
loadPdfViewer('#root');
Optional
pageIndex: numberIssues the next search result, primarily used internally by the PDF Searcher.
A Promise that resolves with the processed search result.
The search result to be processed.
The cancellation token to handle the possibility of cancellation.
Asynchronously generates search results based on the provided search options.
// Highlight all search results without opening SearchPanel.
const searchIterator = viewer.searcher.search({ Text: "test", MatchCase: true, HighlightAll: true });
searchIterator.next();
searcher.applyHighlight();
// Iterate all search results
const searcher = viewer.searcher;
var searchResults = [];
const searchIterator = searcher.search({ Text: textToSearch, MatchCase: true });
var searchResult = await searchIterator.next();
if (searchResult.value)
searcher.highlight(searchResult.value)
while (searchResult.value && !searchResult.done) {
const searchResultValue = searchResult.value;
searchResults.push(`index: ${searchResultValue.ItemIndex}, text: ${searchResultValue.DisplayText}, pageIndex: ${searchResultValue.PageIndex}`);
searchResult = await searchIterator.next();
}
console.log("Search results: " + (searchResults.length ? searchResults.join("; ") : "No search results"));
// Open the document, find the text 'wildlife' and highlight the first result:
async function loadPdfViewer(selector) {
var viewer = new DsPdfViewer(selector, { restoreViewStateOnLoad: false });
viewer.addDefaultPanels();
var afterOpenPromise = new Promise((resolve)=>{ viewer.onAfterOpen.register(()=>{ resolve(); }); });
await viewer.open('wetlands.pdf');
await afterOpenPromise;
var findOptions = { Text: 'wildlife' };
var searchIterator = await viewer.searcher.search(findOptions);
var searchResult = await searchIterator.next();
viewer.searcher.cancel();
viewer.searcher.highlight(searchResult.value);
}
loadPdfViewer('#root');
// Open the document, find the text 'wildlife' and print search results to the console:
async function loadPdfViewer(selector) {
var viewer = new DsPdfViewer(selector);
viewer.addDefaultPanels();
await viewer.open('wetlands.pdf');
await (new Promise((resolve)=>{
viewer.onAfterOpen.register(()=>{
resolve();
});
}));
var findOptions = {
Text: 'wildlife',
MatchCase: true,
WholeWord: true,
StartsWith: false,
EndsWith: false,
Wildcards: false,
Proximity: false,
SearchBackward: false,
HighlightAll: true
};
var searcher = viewer.searcher;
var searchIterator = await searcher.search(findOptions);
var resultsCount = 0;
var searchResult;
do {
searchResult = await searchIterator.next();
if (searchResult.value) {
// this could be either result or progress message (ItemIndex < 0)
if(searchResult.value.ItemIndex >= 0) {
console.log('next search result:');
console.log(searchResult.value);
resultsCount++;
} else {
const pageCount = _doc.pageCount.totalPageCount || _doc.pageCount.renderedSoFar;
console.log('search progress, page index is ' + searchResult.value.PageIndex);
}
}
else {
console.log("Search completed");
break;
}
}
while(!searchResult.done);
console.log('Total results count is ' + resultsCount);
}
An asynchronous iterable iterator that yields search results.
Search options to customize the search.
The (current) normalized search query.
Gets highlightAll option.
Sets highlightAll option.
Gets selected search result.
Gets selected search result index. Returns -1 if nothing is selected.
Retrieves non-empty searcher options.
The current state of the PDF searcher options, ensuring that it is a valid object.
Gets total search results count.
Gets total search results count promise.
PDF document searcher. Generates asynchronous search results (see search method). The GcPdfSearcher API was designed to be used internally with Search Panel UI.