使用JSPDF Autotable在文本之前将图像添加到单元格中

发布于 2025-01-27 10:08:29 字数 1088 浏览 3 评论 0原文

我想将图像放在该单元格的同一单元格中。但是我不知道该怎么做。我尝试放置的图像永远不会相同。目前,我尝试了一个随机图像,但是我不知道如何将文本移到图像之后。我什至不确定这是可能的。这是我的代码的一部分:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空城旧梦 2025-02-03 10:08:29

我自己解决了问题。

  1. 我需要做的是在左侧添加图像
    我想将图像放入。

    的边界

  2. 最后,我将左填充物设置为图片的大小。

  3. 现在,我可以在文本之前拥有图像。

I resolved my problem by myself.

  1. 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.

  2. Then I set the minheight of the cell to the heigth of the pic.

  3. Finally, I set the left padding to size of picture.

  4. Now, I am able to have an image before the text.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文