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.
Show config properties
string
required
Query text.
string
Page index range to search (e.g., "0-5, 7, 9-12", "all"). Page references are zero-indexed. If omitted, searches all pages.
A Promise that resolves to the current selection, or undefined if there is no selection.
Example
async function getSelectedText() { return webViewer.text.getSelected();}function success(result) { if (result) { console.log(`Text is: ${result.text}`); console.log(`Page index is: ${result.pageIndex}`); let rects = result.rects; console.log(`rect[0] metrics:\ntop=${rects[0].top}\nright=${rects[0].right}\nbottom=${rects[0].bottom}\nleft=${rects[0].left}`); }}function failure(error) { console.error(`Error: ${error}`);}getSelectedText().then(success, failure);