Programmatically highlight text upon searching

Hi Team,

We have implemented pdfjs express and are using the search function. We wish to extend our use case by being able to programmatically highlight text in the document once found. We have been trying to achieve this by searching the text first and then upon found text, consider using Highlight Annotations to achieve this. We have hit a road block given we need the X,Y positions of the highlight section and its width and height and all we have from search text callback is quads.

Can we please get some advice on how we can best achieve this?

Best,
Chitrang

Hi Chitrang,

Thanks for contacting us regarding PDFJS Express!

Fortunately, the information that quads contain is good enough to programmatically create a highlight annotation.

We have a text-position sample that shows the code you might be interested in. The sample is available under the samples/advanced/text-position folder in the download package from https://pdfjs.express/documentation/get-started/manually.

The function in the sample that you want to take a look at is highlightText.

Let me know how this works and if you have any other questions!

Best Regards,
Zhijie