Annotation's getContext() always returns undefined for text annotations

Which product are you using?
PDF.js Express Plus

PDF.js Express Version
8.4.1

Detailed description of issue
Whenever I try to access the selected text for a text annotation using annotation.getContext(), it returns undefined. However I’m able to get this text using annotation.getCustomData(‘trn-annot-preview’)

Expected behaviour
annotation.getContext() returns the selected text snippet

Does your issue happen with every document, or just one?
It happens with every document

Link to document
Any PDF document

Code snippet

import WebViewer from '@pdftron/pdfjs-express';

function loadDocumentViewer(blob, params, viewer) {
    WebViewer(
        params,
        viewer.nativeElement
    ).then((instance) => {
        instance.UI.loadDocument(...);
        customizeAnnotationsPanel(instance);
    });
}

function customizeAnnotationsPanel(viewerInstance) {
    viewerInstance.UI.dangerouslySetNoteTransformFunction(
        (wrapper, state, createElement) => {
            const div = createElement('div');
            const copySnippetButton = createElement('button');

            copySnippetButton.onclick = () => {
                copySnippet(state);      
            };

            div.appendChild(copySnippetButton);
            wrapper.appendChild(div);
        }
    );
}

function copySnippet(state) {
    const annotationMetadata = {
        source_text_snippet: state.annotation.getContents(),
    };
    navigator.clipboard.writeText(JSON.stringify(annotationMetadata));
}

Hello polina.meleca,

I was able to reproduce getContents() returning undefined, we have added this to our backlog.

Best regards,
Tyler Gordon
Web Development Support Engineer
PDFTron


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

@tgordon I am writing to follow up on the issue reported by my colleagues, has it been adddressed?
Thanks,
Ons.

Hello ons.othmen,

Looks like it has been fixed, can you try with the latest build?
image

Best regards,
Tyler Gordon

The contents is still blank for 8.7.0. We create annotations using text highlight tool.

Hello polina.meleca,

This thread is specifically for the FreeText tool, in your case you’re using the highlighting tool

Best regards,
Tyler

Sorry for unclear description, but the initial problem was for the AnnotationCreateTextHighlight tool