Skip to content

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

@w-1-j-g

Description

@w-1-j-g
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;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions