根据先前的图像/文本位置在另一个下方添加图像和文本
Posted
技术标签:
【中文标题】根据先前的图像/文本位置在另一个下方添加图像和文本【英文标题】:Adding images & texts one below another based on previous image /text position 【发布时间】:2022-01-18 20:25:56 【问题描述】:jspdf中如何通过计算y坐标顺序添加图片或文字
Here is the demo code
我找不到任何方法可以帮助我计算上一张图像的 Y 坐标,以便我可以在其后添加下一张图像或文本
doc.text('Something written over here', 15, 18);
doc.addImage(base64_img, 10, 20, 0, 0); // should be added with y position based on text that ends above it.
doc.addImage(base64_img, 10, 40, 0, 0); // < 40 should be some val that should be next value of Y after 1st image
doc.addImage(base64_img, 10, 70, 0, 0);
【问题讨论】:
【参考方案1】:您可以尝试“玩”字符的大小和字符串的长度,如下所示:
const yourText = 'Something written over here';
const sizeChar = 20;
const textWith = yourText.length * sizeChar;
doc.setFontSize(sizeChar);
doc.text(yourText, 15, 18);
doc.addImage(base64_img, 10, textWith, 0, 0);
【讨论】:
以上是关于根据先前的图像/文本位置在另一个下方添加图像和文本的主要内容,如果未能解决你的问题,请参考以下文章