How to give pdf.js worker in Angular CLI application

后端 未结 5 772
醉酒成梦
醉酒成梦 2021-01-06 21:53

I used pdf.js directly in angular app for some pdf purposes. It works fine.

I imported the pdfjs from the pdfjs-dist and my package.json includes pdfjs-dist.

5条回答
  •  伪装坚强ぢ
    2021-01-06 22:05

    This is because you did not set the GlobalWorkerOptions.workerSrc property. Normally you set it to the URL from where the pdf.worker.js or pdf.worker.min.js file can be loaded. If you installed the pdfjs-dist packages it is in the same folder as pdf.js.

    Try it out, as soon as you set the property the warning goes away.

    PDFJS.GlobalWorkerOptions.workerSrc = 
          "./node_modules/pdfjs-dist/build/pdf.worker.js";
    

    In production you should load it from a CDN URL.

提交回复
热议问题