PDF JS无法加载工作者

时间:2018-09-25 16:48:10

标签: javascript pdfjs

我正在尝试使用pdfjs渲染pdf。它可以正常工作,但是在加载脚本时出现404错误:enter image description here

我以这种方式呼叫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))

enter image description here

导入错误还是应该手动添加worker.js?

1 个答案:

答案 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
});