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));
}