loopingnoob
loopingnoob

Reputation: 3

Cell text colour refuses to change jsdpdf-autotable

I have followed the steps to some answers on this topic already, but none of them are working. I have the following text which needs to display in a red text:

<table id="heading1">
<tr>
<td class="hrow"><h4>1. DETAILS</h4></td>
</tr>
</table>

Here is the code I have written for the PDF:

<script>
 exportGraph = function () {
 var pdfsize = 'a4';
 var pdf = new jsPDF('l', 'mm', pdfsize);
 var totalPagesExp = "{total_pages_count_string}";

 var res2 = pdf.autoTableHtmlToJson(document.getElementById("heading1"));

 pdf.autoTable(res2.columns, res2.data, {
    createdCell: function(cell, data) {
        var tdElement = cell.raw;
        if (tdElement.classList.contains("hrow")) {
            cell.styles.textColor = "[255,72,72]";
        }
    },
startY: 10,
margin: {left: 5 },
styles: { halign: 'left', fontsize: 12 }
});


pdf.save('Submission-Printout.pdf'); 

}

</script>

As you can see, what I have done SHOULD in theory work, but the text still appears as not red. Does anyone know why it's not appearing in red text colour?

Upvotes: 0

Views: 1203

Answers (1)

Marc Jonkers
Marc Jonkers

Reputation: 506

What about this example ?

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

  var elem = document.getElementById('example');
  var data = doc.autoTableHtmlToJson(elem);
  doc.autoTable(data.columns, data.rows, {
     createdCell: function (cell, data) {
      if ($(cell.raw).hasClass("demo1")) {
        cell.styles.textColor = [200, 0, 0];
                    cell.styles.fontStyle = 'bolditalic';
            };
      if ($(cell.raw).hasClass("demo2")) {
        cell.styles.textColor = [0, 0, 205];
                    cell.styles.fontStyle = 'bold';
            };
       return false;
     }
}); 
 doc.save("table.pdf");
}

Upvotes: 1

Related Questions