配置:
//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 :
什么地方出了错? (添加截图)
这些示例已经使用这种新的 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});
最有用的评论
来到这里是因为我在从 v1 升级到 v2 时遇到了这个错误:
简而言之,我们现在必须明确引用
.promise