Skip to main content
The text object is an instance accessible from the main MuPDFWebViewer instance as follows:
This assumes you have returned your instance name as webViewer from the initMuPDFWebViewer() promise!

text

The text object has the following methods:
Searches for text.

Parameters

object
required
The configuration object.

Returns

Promise<{ results: { words: { prefix: string; keyword: string; suffix: string; redMarked: boolean; rects: TRect[] }[], pageIndex: number }[] }
required
A Promise that resolves to search results grouped by page.
Example

locateSource

Searches for the given text and returns its coordinates for highlighting. This is designed to be used with LLM-generated answers that include quoted source text, allowing you to map that text back to the PDF for highlighting. The input text is expected to be high-quality Markdown from an LLM response.

Parameters

object
required
The configuration object.

Returns

Promise<{ pageIndex: number; words: [{ rects: TRect[] }] }>
required
A Promise that resolves to the matched word rects for highlighting.
Example
Refer to Source Locator: Example for a more detailed example.

getSelected

Gets the currently selected text from a document. If there is no selected text then it returns undefined.

Returns

Promise<{ text: string, pageIndex: number, rects: TRect[] } | undefined>
required
A Promise that resolves to the current selection, or undefined if there is no selection.
Example