简体   繁体   English

如何在 PDF.js 中使用注解层?

[英]How to use annotation layer in PDF.js?

Some of the PDF.js code mentions an "annotation layer", for example AnnotationLayerBuilder here:一些 PDF.js 代码提到了一个“注释层”,例如 AnnotationLayerBuilder 这里:

https://github.com/mozilla/pdf.js/blob/95e102c07bc257c2120fd7fd9141762b2c813a1c/web/annotation_layer_builder.js#L118 https://github.com/mozilla/pdf.js/blob/95e102c07bc257c2120fd7fd9141762b2c813a1c/web/annotation_layer_builder.js#L118

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.还有pdfDocument.annotationStoragepdfjsLib.AnnotationLayer ,它们 - 在我尝试过的所有文档中 - 都是空的,即使在确实有文本注释的文档中也是如此。

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:)我找不到关于注释层的任何示例或文档以及它应该如何使用,但它确实听起来很有趣:)

  1. 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? 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第 8.4 节注释? Or, is it something internal to PDF.js?或者,它是 PDF.js 内部的东西吗?

  2. How do I list the existing annotations from javascript code in PDF.js, and how do I add one?如何在 PDF.js 中列出 javascript 代码中的现有注释,以及如何添加一个? (just for display; not expecting to be able to save it in the pdf, of course) Can anyone provide a working code example? (只是为了显示;当然,不希望能够将其保存在 pdf 中)任何人都可以提供一个工作代码示例吗?

Thanks!谢谢!

Annotations are standard for the PDF file format as described in the links you provided.如您提供的链接中所述,注释是 PDF 文件格式的标准。 They are not a new concept to PDF.js.它们对于 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.我正在构建一个视图层来替换 PDF.js 团队构建的查看器。 The basic idea there is you:你的基本想法是:

  1. Get a reference to the PDFDocumentProxy object via const doc = getDocument(url)通过const doc = getDocument(url)获取对 PDFDocumentProxy object 的引用
  2. Get a reference to a PDFPageProxy object via const page = await doc.getPage(num)通过const page = await doc.getPage(num)获取对 PDFPageProxy object 的引用
  3. Get the annotations via await page.getAnnotations()通过await page.getAnnotations()获取注解

If you're already using the viewer they built, it doesn't appear to be exposed anywhere.如果您已经在使用他们构建的查看器,它似乎不会暴露在任何地方。

I have figure out how to add annotation using pdf.js.我已经弄清楚如何使用 pdf.js 添加注释。 Demos: https://demos.libertynlp.com/#/pdfjs-annotation演示: https://demos.libertynlp.com/#/pdfjs-annotation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM