Vue.use(pdfjsLib);
在组件中引用了pdf.worker.mjs
[JavaScript] 纯文本查看 复制代码methods: {
async loadPDF() {
// 引入worker.js
pdfjsLib.GlobalWorkerOptions.workerSrc =
"../../static/pdfjs-dist/pdf.worker.mjs";
const loadingTask = pdfjsLib.getDocument(
"https://minio.yndth.tech/bilateral-trade-mall%2Fvoucher-file%2Fpdf%2F2d41d0d19cc993dda4fdc070d779ecbc.pdf"
);
try {
const pdf = await loadingTask.promise;
this.renderPDF(pdf);
} catch (error) {
console.error("Error loading PDF", error);
}
},
async renderPDF(pdf) {
const canvas = uni.createCanvasContext("pdf-canvas", this);
for (let pageNum = 1; pageNum
最后渲染PDF的时候uniapp报错:Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'width')
[i]
已知是由下面这行代码引发的width和height没找到报错的(也就是pdf组件的render方法没有找到宽高导致的)
[JavaScript] 纯文本查看 复制代码await page.render({ canvasContext: canvas, viewport }).promise;
花了1天的时间没有找到解决方法,求大佬帮帮忙,分不够随时可加