Log the clicked word to console

Which product are you using?
PDF.js Express Viewer

PDF.js Express Version
8.7.0

Detailed description of issue
I would like to log the clicked word in the PDF to console.

Expected behaviour
The text will be logged to console.

Hi there,

Thank you for contacting pdf.js express forums,

What do you mean by clicking the word? Do you mean an annotation’s text contents? Buttons on the UI? Text content in the PDF?

If you mean annotations, you can call the annotationManager and select it to view the annotation properties:

If you mean selected text in pdf, you can use getSelectedText method:
https://pdfjs.express/api/Core.DocumentViewer.html#getSelectedText__anchor

Best regards,
Kevin Kim


Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here

Hi Kevin,

thank you for your message and the provided information.

My PDF looks like this (small section of the whole PDF):
Bildschirm­foto 2022-11-10 um 10.25.33.png

There are drawings and numbers / text.
My goal is: When I click on any number / text, I would like to print it in the console.
I don’t need any editing or annotation, just to view the PDF and get the numbers in the console back, if somebody clicks them.

Is this possible?

Thank you so much!

Best regards

Hi there,

Thank you for your response,

This is tricky because when clicking an area inside the documentViewer, we only have access to the page number and hence, coordinates of the document of the area:
This guide shows you the events that we have on clicking the documentViewer area:

https://pdfjs.express/api/Core.DocumentViewer.html#event:click

However, if those numbers / text are annotations, then we have access to the ‘annotationSelected’ event and thus have access to the text properties inside of them.

I hope that answers your question.

Best regards,
Kevin Kim


Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here

Hi Kevin,

thank you very much for sharing your ideas!
Thank you for your time and expertise.

Unfortunately this doesn’t help. But I will go on and check how I can solve this. If I find a solution, I will share it here to you.

Thanks!