# Log the clicked word to console

**URL:** <https://pdfjs.community/t/log-the-clicked-word-to-console/2151>\
**Category:** Technical Support\
**Created:** [November 9, 2022, 9:31pm UTC](https://pdfjs.community/t/log-the-clicked-word-to-console/2151 "2022-11-09T21:31:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomatoJohn](https://avatars.discourse-cdn.com/v4/letter/t/6a8cbe/32.png) [@tomatoJohn](https://pdfjs.community/u/tomatoJohn)\
**Post date:** [November 9, 2022, 9:31pm UTC](https://pdfjs.community/t/log-the-clicked-word-to-console/2151/1 "2022-11-09T21:31:31Z")

</div>

**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.

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [November 9, 2022, 10:40pm UTC](https://pdfjs.community/t/log-the-clicked-word-to-console/2151/3 "2022-11-09T22:40:03Z")

</div>

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:

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/6/6461ef7d0e2e509695f4bf46dfd1ddffb2b18220.png)

If you mean selected text in pdf, you can use getSelectedText method:  
[https://pdfjs.express/api/Core.DocumentViewer.html#getSelectedText\_\_anchor](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](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![tomatoJohn](https://avatars.discourse-cdn.com/v4/letter/t/6a8cbe/32.png) [@tomatoJohn](https://pdfjs.community/u/tomatoJohn)\
**Post date:** [November 10, 2022, 11:51am UTC](https://pdfjs.community/t/log-the-clicked-word-to-console/2151/5 "2022-11-10T11:51:26Z")

</div>

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](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/f/fe4c120c455d77235d10d8653344a606269a2db3.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

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [November 10, 2022, 4:33pm UTC](https://pdfjs.community/t/log-the-clicked-word-to-console/2151/6 "2022-11-10T16:33:03Z")

</div>

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:

> **[PDF.js Express Viewer Coordinates | Documentation](https://pdfjs.express/documentation/viewer/coordinates.8#in-practice)**

[https://pdfjs.express/api/Core.DocumentViewer.html#event:click](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.

> **[Add Events to Annotations with PDF.js Express | Documentation](https://pdfjs.express/documentation/annotation/annotation-events)**

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](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![tomatoJohn](https://avatars.discourse-cdn.com/v4/letter/t/6a8cbe/32.png) [@tomatoJohn](https://pdfjs.community/u/tomatoJohn)\
**Post date:** [November 12, 2022, 9:59pm UTC](https://pdfjs.community/t/log-the-clicked-word-to-console/2151/7 "2022-11-12T21:59:50Z")

</div>

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!
