ComPDFKit Web SDK
    Preparing search index...

    Class TextManager

    Page text cache, text selection state and text hit testing for a document viewer. Coordinates are unrotated page coordinates (top-left origin, PDF points).

    Index
    • onSelectionChanged: the selection changed (DocumentViewer fires textSelected and redraws the selection)

      Parameters

      • OptionaldocViewer: DocumentViewer
      • OptionalonSelectionChanged: (pages: number[]) => void

      Returns TextManager

    • Clears the selection; does nothing when nothing is selected.

      Returns void

    • Text range the engine selects in reading order between two points (unrotated page coordinates), page text indexes [start, end); null when no characters are selected. Used by the 2.x compatibility layer to select text the same way as the 2.x API.

      Parameters

      • pageNumber: number
      • pt1: { x: number; y: number }
        • x: number

          Horizontal position in page coordinates.

        • y: number

          Vertical position in page coordinates.

      • pt2: { x: number; y: number }
        • x: number

          Horizontal position in page coordinates.

        • y: number

          Vertical position in page coordinates.

      Returns Promise<[number, number] | null>

    • Selected text; with a page number only that page. Pages are joined with \n (pages not cached cannot be read)

      Parameters

      • OptionalpageNumber: number

      Returns string

    • Returns the current selection.

      Returns TextSelection

      Anchor, focus and the selected character ranges per page.

    • Points the selection end handles point at (page coordinates): the start is the bottom-left of the first line, the end the bottom-right of the last line; mid is the middle of that line (only for pages with cached text and selected characters; null otherwise)

      Returns { end: HandleSpot; start: HandleSpot } | null

      • { end: HandleSpot; start: HandleSpot }
        • end: HandleSpot

          Spot of the end handle: bottom-right of the last selected line.

        • start: HandleSpot

          Spot of the start handle: bottom-left of the first selected line.

      • null
    • Which character the point is on: among lines the point falls into vertically (after extending by tolerance), first the vertically nearest, then the horizontally nearest line; within the line, binary search by x; null when the page text is not cached or no line is nearby

      Parameters

      • pageNumber: number
      • pt: { x: number; y: number }
        • x: number

          Horizontal position in page coordinates.

        • y: number

          Vertical position in page coordinates.

      • Optionaltolerance: number

      Returns TextHit | null

    • Drops the cache of these pages (all when omitted); in-flight results are discarded

      Parameters

      • OptionalpageNumbers: number[]

      Returns void

    • Loads the text of a page, from the cache when available.

      Parameters

      • pageNumber: number

        Page number (1-based).

      Returns Promise<PageText>

      The page text.

    • Returns cached page text without loading it.

      Parameters

      • pageNumber: number

        Page number (1-based).

      Returns PageText | undefined

      The page text, or undefined when it is not cached.

    • fire-and-forget, queued at P3

      Parameters

      • pageNumbers: number[]

      Returns void

    • The Worker searches page text page by page and streams results back (in page order, reversed with SEARCH_UP); closing the iterator (break / return) cancels

      Parameters

      • pattern: string
      • mode: SearchMode
      • OptionalpageNumbers: number[]

      Returns AsyncIterable<SearchResult>

    • Internal: like search, but one chunk per page (including pages without matches); DocumentViewer reports the end of each page from it

      Parameters

      • pattern: string
      • mode: SearchMode
      • OptionalpageNumbers: number[]

      Returns AsyncIterable<{ pageNumber: number; results: SearchResult[] }>

    • Changes the text cache limits and evicts pages that no longer fit.

      Parameters

      • options: TextCacheOptions

        Limits to change; others keep their current values.

      Returns void

    • Selection from anchor to focus (charIndex is the caret position: before which character), may span pages and be reversed

      Parameters

      Returns void

    • Number of cached pages, bytes and in-flight requests

      Returns {
          bytes: number;
          pages: number;
          queued: { interactive: number; prefetch: number };
      }

      • bytes: number

        Approximate bytes used by the cache.

      • pages: number

        Number of cached pages.

      • queued: { interactive: number; prefetch: number }

        Text requests in flight, by priority.

        • interactive: number

          Requests at interactive priority.

        • prefetch: number

          Prefetch requests.