annotation.getContents() is returning undefined

Product: PDFTron Webviewer

Product Version:8.9.0

Please give a brief summary of your issue:
annotation.getContents() is returning undefined even if there is a text in annotation.


I am currently using 8.1.0 version of PDFTron and now upgrading it to 8.9.0 version.

I have a scenario where in 8.1.0 version I am highlighting the text in green colour when user is selecting some text, this i am doing it by using the ToolMode “AnnotationCreateTextHighlight” and adding green color. Hence when user select text it will be Highlighted in green color.
Now when user click on the annotation or text highlighted in green I have to get the text of it. In 8.1.0 version i am doing it as below using the ''annotationSelected" event listener

(annotations, action) => {
this state.viewerInstance?.Core.annotationManager
.get selected annotations()
.map(annotation => {
console.log('text selected: ', annotation.getContents());

The above code was printing the text selected in 8.1.0 After upgrading it to 8.9.0 its not printing the text selected annotation.getContents() is returning undefined.

Can you please help me on this?


This behavior was changed in 8.2: Apryse Documentation | Documentation

In order to get the behavior that you want, please use below code when instantiating WebViewer.

instance.Core.Tools.TextAnnotationCreateTool.AUTO_SET_TEXT = true;

Best Regards,

Hi Will,

Thanks for the response i am able to achieve my functionality now