我想将pdf预览为画布,但我无法在我的项目中导入pdfjs-dist。
我已经使用$yarn add pdfjs-dist
安装了pdfjs-dist
我还需要进口什么吗?
import pdfjsLib from "pdfjs-dist/build/pdf"; //<-- Here is the problem.
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://mozilla.github.io/pdf.js/build/pdf.worker.js';
Could not find a declaration file for module 'pdfjs-dist/build/pdf'. 'd:/pdf-genarator/node_modules/pdfjs-dist/build/pdf.js' implicitly has an 'any' type.
如果我移除../build/pdf
;
import pdfjsLib from "pdfjs-dist";
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://mozilla.github.io/pdf.js/build/pdf.worker.js';
这里没有显示错误,但当我运行它时,控制台显示
Uncaught TypeError: Cannot read properties of undefined (reading 'GlobalWorkerOptions') . . .
尝试导入:
import * as pdfjs from 'pdfjs-dist/es5/build/pdf';
import pdfjsWorker from 'pdfjs-dist/es5/build/pdf.worker.entry';
pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;
const pdfjsLib = pdfjs;