Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

当图像过多的时候,就加载不出来了,也没有报错 #1729

Open
w-1-j-g opened this issue Feb 27, 2025 · 0 comments
Open

当图像过多的时候,就加载不出来了,也没有报错 #1729

w-1-j-g opened this issue Feb 27, 2025 · 0 comments

Comments

@w-1-j-g
Copy link

w-1-j-g commented Feb 27, 2025

imgArr: [
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
{ url: csJpg, description: '图 1.1-1 地理位置平面图', width: 800, height: 500 },
] for (const img of data.imgArr) {
const imageBuffer = await fetch(img.url).then((res) => res.arrayBuffer());
const image = await pdfDoc.embedJpg(imageBuffer);
const imgWidth = 300;
const imgHeight = 150;
const allWidth = (config.width - imgWidth) / 2; // 使图片居中
if (startY < imgHeight + 61.89) { // 如果剩余空间不足,重启一页
page = pdfDoc.addPage([config.width, config.height]);
startY = config.startY;
}
page.drawImage(image, {
x: allWidth,
y: startY - imgHeight - 5,
width: imgWidth,
height: imgHeight,
});
startY -= imgHeight + 6; // 图片下方留一些空隙

            page.drawText(img.description, {
                x: (config.width - Font2.widthOfTextAtSize(img.description, config.size)) / 2,
                y: startY - 20,
                size: config.size,
                font: Font2,
                color: config.color,
            });
            startY -= lineHeight;
        } 使用的是vue3,pdf-lib版本为1.17.1,图片数量一多就无法生成,不知道是什么原因,麻烦帮忙看看
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant