I want to highlight sentence on mouse hover on each word of that sentence in pdf document, i tried some way but i couldn't achieve this goal.
Is there any way to do this with pdftron?
I want to complete this event handler:
WebViewer({
path: '/assets/plugins/pdftron',
initialDoc: '/practical.pdf',
fullAPI: true,
disableLogs: true
}, document.getElementById('pdf'))
.then((instance) => {
const { PDFNet, docViewer } = instance;
const Tools = instance.Tools;
docViewer.on('mouseMove', (e) => {
console.log(e);
});
});
You may be able to use text extractor to get the text from the page and then iterate over it to find which part corresponds to the position of the mouse https://www.pdftron.com/documentation/web/guides/extraction/text-extract/#advanced-text-extraction-from-a-page-region
You'll probably need to convert the mouse coordinates to window coordinates https://www.pdftron.com/documentation/web/guides/coordinates/#converting-between-mouse-locations-and-window-coordinates, window coordinates to page coordinates https://www.pdftron.com/documentation/web/guides/coordinates/#converting-between-window-and-viewer-page-coordinates and finally page coordinates to PDF page coordinates https://www.pdftron.com/documentation/web/guides/coordinates/#converting-between-pdf-and-viewer-coordinates to compare with the values from text extractor