Get wrong text position by getTextPosition


Product Version:
@pdftron/webviewer”: “^8.0.0”

Please give a brief summary of your issue:
Get wrong text position by getTextPosition

Please describe your issue and provide steps to reproduce it:

Hi! I would like search a text then add an annotation at the position of text
I follow this article Get text position in PDF documents
and I use the webviewer-react-sample that you provide and try to implement the feature

here is my sample code

const doc = documentViewer.getDocument();
        const searchTerm = 'Vendor Lock-in';
        const pageNumber = documentViewer.getPageCount()
        const pageText = await doc.loadPageText(pageNumber);
        console.log('pageNumber', pageNumber);
        console.log('pageText', pageText);
        let startIndex = 0;
        let endIndex = 0;
        let quads;
        while (startIndex > -1) {
          startIndex = pageText.indexOf(searchTerm, endIndex);
          endIndex = startIndex + searchTerm.length;
          quads = await doc.getTextPosition(pageNumber, startIndex, endIndex);

        const annotation = new Annotations.TextHighlightAnnotation();
        annotation.PageNumber = pageNumber;

        annotation.Quads = quads;
        annotation.StrokeColor = new Annotations.Color(136, 39, 31);

as you can see the TextHighlightAnnotation should show up the same position as the text “Vendor Lock-in” that I search for, however the annotation show up on the left-top of page always, even I search another text on another page, annotation always show up on the left-top of page
do you have any suggestions for the case thanks

Please provide a link to a minimal sample where the issue is reproducible:


When opening the link you provided, I am seeing a blank page as shown in the attached screenshot. Could you double check your sample please? Also, are you able to reproduce with the latest version with WebViewer?