How to get click text and info from added textpopup?

Good day,

I tried to add a textpopup and I would like to get the selected text and info once click the Add Tag button, just like the other textPopup button it triggers the event annotationSelected.

instance.UI.textPopup.add({
type: ‘actionButton’,
label: ‘AddTag’,
onClick: () => console.log(‘clicked’),
},

Thanks.

Hello Mary,

You can use the getSelectedText API under documentViewer to do this.

https://pdfjs.express/api/Core.DocumentViewer.html#getSelectedText__anchor

instance.UI.textPopup.add({
        type: 'actionButton',
        label: 'AddTag',
        onClick: () => {
          const selectedText = instance.Core.documentViewer.getSelectedText();
          console.log(selectedText);
        }
});

Best Regards,
Darian

I tried it and it works. Thank you.