我想预览pdf作为画布,但我不能导入pdfjs在我的项目。
我已经使用$yarn add pdfjs-dist安装了pdfjs
我还需要进口别的东西吗?
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') . . .发布于 2022-11-24 10:20:39
试着进口:
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;https://stackoverflow.com/questions/73619530
复制相似问题