How to give pdf.js worker in Angular CLI application

后端 未结 5 786
醉酒成梦
醉酒成梦 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:18

    I solved this by using the pre-built version pdfjs-dist and including the file pdf.worker.min.js in scripts

        "assets": [
          "src/assets",
          "src/favicon.ico"  
        ],
        "styles": [
          "node_modules/bootstrap/dist/css/bootstrap.min.css",
        ],
        "scripts": [
          "node_modules/bootstrap/dist/js/bootstrap.js",
          "node_modules/pdfjs-dist/build/pdf.worker.min.js"
        ]
      }
    

    then you shoud import the pdfjs-dist

    import * as PDFJS from "pdfjs-dist";
    PDFJS.GlobalWorkerOptions.workerSrc = "pdf.worker.js";
    

提交回复
热议问题