Use extractTextCompleted to extract text in TypeScript PDF Viewer

14 Oct 20251 minute to read

Use the isExtractText property and the extractTextCompleted event to extract page text along with bounds.

The following example shows how to enable text extraction and handle the completion event:

viewer.isExtractText = true;
viewer.extractTextCompleted = args => {
    //Extract the Complete text of load document
    console.log(args);
    console.log(args.documentTextCollection[1]);
    //Extract the Text data.
    console.log(args.documentTextCollection[1][1].textData);
    //Extract Text in the Page.
    console.log(args.documentTextCollection[1][1].pageText);
    //Extracts the first text of the PDF document along with its bounds
    console.log(args.documentTextCollection[1][1].textData[0].Bounds);
};

Find the sample: How to extract text