Some of the PDF.js code mentions an "annotation layer", for example AnnotationLayerBuilder here:
There is also pdfDocument.annotationStorage
and pdfjsLib.AnnotationLayer
, which - on all the documents I've tried - are empty, even in documents which do have text annotations.
I couldn't find any examples or documentation on the annotation layer and how it is supposed to be used, but it sure sounds interesting :)
What is the annotation layer? Is this talking about standard PDF annotations, as described in https://pspdfkit.com/blog/2018/what-are-annotations/ or https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf section 8.4 Annotations? Or, is it something internal to PDF.js?
How do I list the existing annotations from javascript code in PDF.js, and how do I add one? (just for display; not expecting to be able to save it in the pdf, of course) Can anyone provide a working code example?
Thanks!
Annotations are standard for the PDF file format as described in the links you provided. They are not a new concept to PDF.js.
How you get the annotations will depend on your situation. I'm building a view layer to replace the viewer the PDF.js team built. The basic idea there is you:
const doc = getDocument(url)
const page = await doc.getPage(num)
await page.getAnnotations()
If you're already using the viewer they built, it doesn't appear to be exposed anywhere.