Skip to content
Advertisement

Add image in cell before text with JsPDF AutoTable

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement