Pdf.js: 已弃用的 API 使用示例

创建于 2018-12-24  ·  4评论  ·  资料来源: mozilla/pdf.js

配置:

  • 网络浏览器及其版本:Firefox 64.0
  • 操作系统及其版本:Windows 10
  • PDF.js 版本:'2.6.1'(由//mozilla.github.io/pdf.js/build/pdf.js直接包含)
  • 是否为浏览器扩展:否

重现问题的步骤:
1. 包括通过
- <script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
2.设置:
- pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';
3. 使用示例来自: https :

什么地方出了错? (添加截图)

99733b699429b48a9982577efb14fdde

1-other

最有用的评论

来到这里是因为我在从 v1 升级到 v2 时遇到了这个错误:

Deprecated API usage:  PDFDocumentLoadingTask.then method, use the `promise` getter instead.

简而言之,我们现在必须明确引用.promise

//V1
const loadPDF = await PDFJS.getDocument(file);
const pages = loadPDF.numPages;


//V2
const loadPDF = await PDFJS.getDocument(file).promise; //<-- simply change it here
const pages = loadPDF.numPages;

所有4条评论

这些示例已经使用这种新的 API 用法进行了更新,只是还没有在 JSFiddle 上。 @yurydelendik您能否使用examples文件夹中的当前代码更新该页面上的所有示例?

固定的

来到这里是因为我在从 v1 升级到 v2 时遇到了这个错误:

Deprecated API usage:  PDFDocumentLoadingTask.then method, use the `promise` getter instead.

简而言之,我们现在必须明确引用.promise

//V1
const loadPDF = await PDFJS.getDocument(file);
const pages = loadPDF.numPages;


//V2
const loadPDF = await PDFJS.getDocument(file).promise; //<-- simply change it here
const pages = loadPDF.numPages;

使用第 1 版方式会导致视口错误:
var viewport = pdfPage.getViewport(scale, rotate);

将其更改为使用 GetViewportParameters :
https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L158

var viewport = pdfPage.getViewport({scale:scale, rotate:rotate});

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

patelsumit5192 picture patelsumit5192  ·  3评论

aaronshaf picture aaronshaf  ·  3评论

azetutu picture azetutu  ·  4评论

AlexP3 picture AlexP3  ·  3评论

hp011235 picture hp011235  ·  4评论