text object is an instance accessible from the main mupdfwv.MuPDFWebViewer instance as follows:
This assumes you have returned your instance name as
mupdf from the initMuPDFWebViewer() promise!text
Thetext object has the following methods:
search
search(config: { keyword: string; caseSensitive?: boolean; useRegex?: boolean; pageRange?: string })
Searches for text.
- Arguments:
- config – The configuration object.
- Arguments:
- keyword – (required) Search keyword.
- caseSensitive – (optional) Whether to be case sensitive.
- useRegex – (optional) Whether to use regular expressions.
- pageRange – (optional) Page index range to search (e.g., “1-5, 7, 9-12”, “all”). If not set will search all pages.
- Returns:
Promise<{ results: { words: { prefix: string; keyword: string; suffix: string; redMarked: boolean; rects: mupdfwv.TRect[] }[], pageIndex: number }[] }.
getSelected
getSelected()
Gets the currently selected text from a document.
If there is no selected text then returns null.
- Returns:
Promise<{ text: string, pageIndex: number, rects: TRect[] }>.
locateSource
locateSource(config: { text: string })
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.
- Arguments:
- config – The configuration object.
-
Arguments:
- text – (required) Query text.
-
Returns:
Promise<{ pageIndex: number, words: { rects: mupdfwv.TRect[] }[] }>.