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.
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);