Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GcPdfSearcher

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

Index

Accessors

_query

  • get _query(): string
  • Returns string

    The (current) normalized search query.

highlightAll

  • get highlightAll(): boolean
  • set highlightAll(checked: boolean): void
  • Gets highlightAll option.

    Returns boolean

  • Sets highlightAll option.

    Parameters

    • checked: boolean

    Returns void

state

totalResultsCount

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

    Returns number

totalResultsCountPromise

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

    Returns Promise<number> | null

Methods

_extractText

  • _extractText(): void
  • Extract all text from pdf document once.

    Returns void

_isEntireWord

  • _isEntireWord(content: any, lineEndings: {}, startIdx: any, length: any): boolean
  • 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
    • startIdx: any
    • length: any

    Returns boolean

_prepareMatches

  • _prepareMatches(matchesWithLength: any, matches: any, matchesLength: any): void
  • 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

applyHighlight

  • applyHighlight(): void
  • Render highlight for the current search result.

    Returns void

cancel

  • cancel(): 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

highlight

  • highlight(searchResult: SearchResult, pageIndex?: undefined | number): 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: SearchResult
    • Optional pageIndex: undefined | number

    Returns void

resetResults

  • resetResults(): void
  • Clear search results. This method must be called when the SearchPanel is closed.

    Returns void

search

  • Generate asynchronous search results.

    Parameters

    Returns AsyncIterableIterator<SearchResult>

updateAllPages

  • updateAllPages(): void
  • Repaint highlight for visible pages.

    Returns void