The text object is an instance accessible from the main mupdfwv.MuPDFWebViewer instance as follows:
const text = mupdf.text;
This assumes you have returned your instance name as mupdf from the initMuPDFWebViewer() promise!

text

The text object has the following methods: search(config: { keyword: string; caseSensitive?: boolean; useRegex?: boolean; pageRange?: string }) Searches for text.
  • Arguments:
    • config – The configuration object.
Config 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; }[]; }.
Example
mupdf.text.search({keyword:"hello"});

// returns e.g.

{
results: {
    words: {
    prefix: string;
    keyword: string;
    suffix: string;
    rects: {
        top: number;
        left: number;
        bottom: number;
        right: number;
    }[];
    }[];
}[];
}

getSelected

getSelected() Gets the currently selected text from a document. If there is no selected text then returns null.
  • Returns: Promise<{ text: string, rect:{} }>.
Example
async function getSelectedText() {
    return mupdf.text.getSelected();
}

function success(result) {
    if (result) {
        console.log(`Text is: ${result.text}`);
        let rect = result.rect;
        console.log(`rect metrics:\nx=${rect.x}\ny=${rect.y}\nwidth=${rect.width}\nheight=${rect.height}\ntop=${rect.top}\nright=${rect.right}\nbottom=${rect.bottom}\nleft=${rect.left}`);
    }
}

function failure(error) {
    console.error(`Error: ${error}`);
}

getSelectedText().then(success, failure);