There is an older response to this question in How can I get the highlighted text from PSPDFKit? but all the links are dead and the solution may have been refactored drastically since 2014.
All I get from the response from instance.exportInstantJSON()
is the coordinates of a rectange annotation of my highlighted annotation, is there any way to resolve these coordinates and get the text being highlighted?
Using PSPDFKit version 2022.3.1
Advertisement
Answer
I dug a bit deeper in the API documentation and found there is a instance.getMarkupAnnotationText
method which does the job.
const annotations = await instance.getAnnotations(0); const markupAnnotations = annotations.filter( annotation => annotation instanceof PSPDFKit.Annotations.MarkupAnnotation ); const text = await Promise.all( markupAnnotations.map(instance.getMarkupAnnotationText) ); console.log(text);