'How to send clicked word to an API call from pdf?

I am creating a react app in next js and ran into a problem. I wanted to click on a word in displayed pdf and send it to an API call. I've seen a few pdf to text solutions before, but they destructurize the document. Is this the only option? All the highlight options in pdfs are just based on a position in canvas.
And another question - how to properly handle this click event. Let's say even that we work with a text document. How to wrap these words so I could use this onClick on them?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source