Javascript `fullReader为null`使用PDF.js加载PDF时出错
我正在使用pdf.js在react中加载pdf。在Javascript `fullReader为null`使用PDF.js加载PDF时出错,javascript,reactjs,pdf.js,Javascript,Reactjs,Pdf.js,我正在使用pdf.js在react中加载pdf。在getDocument中的承诺可以解决之前,我得到一个错误:fullReader为null(在Firefox中)。在Chrome中,我得到一个不同的错误:需要一个函数,这很奇怪,因为我正在传递回调 我尝试了不同的方法导入pdf.js,并查看了多个示例。我能够成功地运行这个示例(),但无法在我自己的应用程序中运行它 导入pdf.js: import * as pdfjsLib from 'pdfjs-dist'; pdfjsLib.GlobalW
getDocument
中的承诺可以解决之前,我得到一个错误:fullReader为null
(在Firefox中)。在Chrome中,我得到一个不同的错误:需要一个函数
,这很奇怪,因为我正在传递回调
我尝试了不同的方法导入pdf.js,并查看了多个示例。我能够成功地运行这个示例(),但无法在我自己的应用程序中运行它
导入pdf.js:
import * as pdfjsLib from 'pdfjs-dist';
pdfjsLib.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.js`;
my component中的componentDidMount
函数:
componentDidMount() {
const loadingTask = pdfjsLib.getDocument(`examplePDFUrl`);
loadingTask.promise.then((doc) => {
console.log(`Document loaded ${doc.numPages} page(s)`);
}, (error) => {
console.error(`Error during loading: ${error}`);
});
}
如果有人对此有任何见解,我将非常感谢您的帮助。谢谢大家! 什么是pdfjs区。。。工作的示例使用了
pdfjs dist/web/pdf_viewer.js
,这是查看器层()。示例是从“pdfjs dist/webpack”(pdfjs dist/webpack)导入。我试过了,但遇到了另一个问题。什么是pdfjs dist
。。。工作的示例使用了pdfjs dist/web/pdf_viewer.js
,这是查看器层()。示例是从“pdfjs dist/webpack”(pdfjs dist/webpack)导入。我试过了,但遇到了另一个问题。