PDF-kit 使用 forEach 循环并排显示图像
我有 API 可以在向数据库发送请求后将图片添加到 pdf 中。如果我发送一张图片,我就能成功,但如何并排显示图像?有可能吗?因为目前我的图像每秒堆叠一个,依此类推...
这是我的代码:
const photosToPdf = [];
for(let j=0;j<uploadsPath.length;j++){
photosToPdf.push(uploadsFileNames[j]);
}
photosToPdf.forEach(v => {
doc.image(`uploads/${v}`, 30, 350, {width: 100});
});
它将采用空数组并用用户上传的图像名称填充它。然后它应该循环遍历该数组并使用文件名作为 img 源。它正在工作,但它看起来像这样,一秒一秒。
我有想法,我将使用另一个循环来生成 X 和 Y 位置并每次都增加它,但也许有更简单的解决方案。
I have API that can add picture to pdf after sending request to database. I managed to make it work if I send one picture, but how can I show images side by side? Is it even possible? Because currently I have images stack one on second and so on...
Here is my code:
const photosToPdf = [];
for(let j=0;j<uploadsPath.length;j++){
photosToPdf.push(uploadsFileNames[j]);
}
photosToPdf.forEach(v => {
doc.image(`uploads/${v}`, 30, 350, {width: 100});
});
It will take empty array and fill it with Images name uploaded by user. Then It should loop through that array and use file name as img source. It is working, but It is looking like this, one on second.
I have idea, that I will use another loop to generate X and Y position and increase it every time, but maybe there is more simple solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过每次迭代增加位置来解决这个问题。
Fixed this problem by incrementing position every iteration.