PDF document searcher. Generates asynchronous search results (see search method). The GcPdfSearcher API was designed to be used internally with Search Panel UI.

Hierarchy

  • GcPdfSearcher

Implements

  • IPdfSearcher

Methods

  • Extract all text from pdf document once.

    Returns void

  • Determine if the search query constitutes a "whole word", by comparing the first/last character type with the preceding/following character type.

    Parameters

    • content: any
    • lineEndings: { [x: number]: boolean }
      • [x: number]: boolean
    • startIdx: any
    • length: any

    Returns boolean

  • 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.

    Parameters

    • matchesWithLength: any
    • matches: any
    • matchesLength: any

    Returns void

  • Render highlight for the current search result.

    Returns void

  • Cancel search task.

    Example

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

    Returns void

  • Navigates to a page containing the result and highlights found text.

    Example

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

    Parameters

    • searchResult: null | SearchResult
    • Optional pageIndex: number

    Returns Promise<void>

  • Checks whether a specific search result is currently selected.

    Returns

    A boolean indicating whether the provided search result is currently selected.

    Parameters

    • result: SearchResult

      The search result to be checked for selection.

    Returns boolean

  • Issues the next search result, primarily used internally by the PDF Searcher.

    Returns

    A Promise that resolves with the processed search result.

    Parameters

    • result: SearchResult

      The search result to be processed.

    • cancellation: any

      The cancellation token to handle the possibility of cancellation.

    Returns Promise<SearchResult>

  • Clear search results. This method must be called when the SearchPanel is closed.

    Returns void

  • Asynchronously generates search results based on the provided search options.

    Example

     // Highlight all search results without opening SearchPanel.
    const searchIterator = viewer.searcher.search({ Text: "test", MatchCase: true, HighlightAll: true });
    searchIterator.next();
    searcher.applyHighlight();

    Example

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

    Example

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

    Example

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

    Returns

    An asynchronous iterable iterator that yields search results.

    Parameters

    • options: FindOptions

      Search options to customize the search.

    Returns AsyncIterableIterator<SearchResult>

  • Toggles the visibility of the Search UI.

    Parameters

    • Optional forceExpand: boolean = true

      Indicates whether to force expanding the Search UI. Default is true.

    Returns void

  • Repaint highlight for visible pages.

    Returns void

Accessors

  • get _query(): string
  • Returns

    The (current) normalized search query.

    Returns string

  • get highlightAll(): boolean
  • Gets highlightAll option.

    Returns boolean

  • set highlightAll(checked: boolean): void
  • Sets highlightAll option.

    Parameters

    • checked: boolean

    Returns void

  • get selectedSearchResult(): undefined | SearchResult
  • Gets selected search result.

    Returns undefined | SearchResult

  • get selectedSearchResultIndex(): number
  • Gets selected search result index. Returns -1 if nothing is selected.

    Returns number

  • get state(): PdfSearcherOptions
  • Retrieves non-empty searcher options.

    Returns

    The current state of the PDF searcher options, ensuring that it is a valid object.

    Returns PdfSearcherOptions

  • get totalResultsCount(): number
  • Gets total search results count.

    Returns number

  • get totalResultsCountPromise(): null | Promise<number>
  • Gets total search results count promise.

    Returns null | Promise<number>