question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to display image from data in column

See original GitHub issue

Hi Man, I have an image in column, how to show it? column_image column_image1

this is : var doc = new jsPDF(‘p’, ‘pt’,‘letter’); var elem = document.getElementById(“tbl-customers”); var res = doc.autoTableHtmlToJson(elem); doc.autoTable(res.columns, res.data, {

      drawRow: function (row, data) {
       var logo = row.index === 7;
       var Imgpath = '$baseurl/upload/'+ logo;

        if (row.index === 7) {                           
          doc.addImage(Imgpath, 'JPEG', data.settings.margin.left, 40, 25, 25);
        }
      }


    });
    doc.save("table.pdf"); 

please help, thanks

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
simonbengtssoncommented, Dec 4, 2015

It can be done something like this. Here is a working codepen. Note that I used src=“datauri” in the html, but it should work with normal urls as well as long as they are local.

function generate() {
  var doc = new jsPDF('p', 'pt');

  var elem = document.getElementById('table');
  var imgElements = document.querySelectorAll('#table tbody img');
  var data = doc.autoTableHtmlToJson(elem);
  var images = [];
  doc.autoTable(data.columns, data.rows, {
    bodyStyles: {rowHeight: 30},
    drawCell: function(cell, opts) {
      if (opts.column.dataKey === 5) {
        var img = imgElements[opts.row.index];
        images.push({
          elem: img,
          x: cell.textPos.x,
          y: cell.textPos.y
        });
      }
    },
    afterPageContent: function() {
      for (var i = 0; i < images.length; i++) {
        doc.addImage(images[i].elem, 'jpg', images[i].x, images[i].y);
      }
    }
  });

  doc.save("table.pdf");
}

I realized while writing this that the hooks system needs some work to be user friendly. I also found a bug that meant that I had to add the images in the afterPageContent hook instead of directly in drawCell as it otherwise got hidden below the table.

0reactions
yadavmohancommented, Mar 8, 2021

Hi simonbengtsson, How can i show dynamic image & data in pdf if i have data in array format currently it will generate the imageUrl in pdf sample dynamic data responseHeader : [[‘No’,‘avatarImage’,‘rationNo’,‘color’]]

responseData 0:[‘1’,‘https://www.w3schools.com/howto/img_avatar.png’,‘3455’,'red’] 1:[‘12’,‘https://www.w3schools.com/howto/img_avatar.png’,‘34’,'blue’]

generategeneratePdf (responseHeader,responseData)

const generatePdf = (responseHeader,responseData) => { const doc = new jsPDF(‘p’,‘pt’); doc.autoTable({ head: responseHeader, body: responseData, }) doc.save(‘table.pdf’); }

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to: Display Images from a Data Field with Image Paths
#Create and Assign the PictureEdit to the Image Column · C# · VB.NET.
Read more >
Display images in a table or matrix in a report - Power BI
Select that column. On the Column tools ribbon, for Data category, select Image URL. ... Add the column to a table, matrix, slicer,...
Read more >
How to display image in column; — DataTables forums
I would like to render an image based on the URL of the image file displayed in the column. <img src="url/image.jpg">.
Read more >
Display images in columns and measures in Power BI table ...
(a) Configure the measure or the column you're going to use (b) Select ' Image URL' in the Data category (c) Image URL...
Read more >
Display images in a table column with data - Stack Overflow
I am working on firebase cloudfirestore and I want to display image in a table column with data. Currently I have tried to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found