我正在尝试使用pdfjs渲染pdf。它可以正常工作,但是在加载脚本时出现404错误:
我以这种方式呼叫pdf js:
import * as PDFJS from 'pdfjs-dist';
pdfCreator: any = PDFJS;
this.pdfCreator
.getDocument(url)
.then((doc) => {
this.doc = doc;
console.log('pdf2')
this.renderPages(canvasContainer, scale);
})
.catch(err => console.log(err))
导入错误还是应该手动添加worker.js?
答案 0 :(得分:0)
尝试以下操作导入工作程序并将其分配给GlobalWorkerOptions
import pdfjsLib from 'pdfjs-dist';
import pdfWorker from 'pdfjs-dist/lib/pdf.worker';
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfWorker;
pdfjsLib.getDocument(src).then(pdf => {
//add your code here
});