使用JSPDF Autotable在文本之前将图像添加到单元格中
我想将图像放在该单元格的同一单元格中。但是我不知道该怎么做。我尝试放置的图像永远不会相同。目前,我尝试了一个随机图像,但是我不知道如何将文本移到图像之后。我什至不确定这是可能的。这是我的代码的一部分:
doc.autoTable({
headStyles: { halign: 'center', fillColor: [0, 63, 204], lineWidth: 0.3, lineColor: [0, 0, 0] },
columnStyles: {
0: { halign: 'center', cellWidth: 60, fillColor: [255, 255, 255], lineWidth: 0.3, lineColor: [0, 0, 0] },
1: { halign: 'center', cellWidth: 'auto', fillColor: [255, 255, 255], lineWidth: 0.3, lineColor: [0, 0, 0] }
},
didDrawCell: function (data) {
var img = "/Content/rtech/img/logo_black_blue.jpg"
var textPos = data.cell.getTextPos();
console.log(data.cell);
doc.addImage(img, 'JPEG', textPos.x, textPos.y, 50, 15); }]);
},
html: '#facTableName-' + i
})
在这种情况下,我将此图像添加到选项卡的每一行中。
希望您能帮助我,谢谢。
I want to put image before text in the same cell of this cell. But I don't know how to do. The images I try to put are never the same size. For the moment, I tried with a random image, but I don't know how to shift the text after the image. I'm not even sure that is possible. Here is a part of my code :
doc.autoTable({
headStyles: { halign: 'center', fillColor: [0, 63, 204], lineWidth: 0.3, lineColor: [0, 0, 0] },
columnStyles: {
0: { halign: 'center', cellWidth: 60, fillColor: [255, 255, 255], lineWidth: 0.3, lineColor: [0, 0, 0] },
1: { halign: 'center', cellWidth: 'auto', fillColor: [255, 255, 255], lineWidth: 0.3, lineColor: [0, 0, 0] }
},
didDrawCell: function (data) {
var img = "/Content/rtech/img/logo_black_blue.jpg"
var textPos = data.cell.getTextPos();
console.log(data.cell);
doc.addImage(img, 'JPEG', textPos.x, textPos.y, 50, 15); }]);
},
html: '#facTableName-' + i
})
In this case, I add this image in each row of the tab.
Hope you will be able to help me, thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己解决了问题。
我需要做的是在左侧添加图像
我想将图像放入。
的边界
最后,我将左填充物设置为图片的大小。
现在,我可以在文本之前拥有图像。
I resolved my problem by myself.
What I needed to do is to add the image at the position of left
border of the cell I wanted to put the image in.
Then I set the minheight of the cell to the heigth of the pic.
Finally, I set the left padding to size of picture.
Now, I am able to have an image before the text.