How to style the table with jspdf

hi,
I have a hard time to modify the style of my table that I want to be generated in pdf(I work with jspdf),this is my code:

function tableToJson(table) {
        var data = [];

        var headers = ["Référence","Nom","Prenom","Email","Adresse de Facturation"];
         specialElementHandlers = {
                // element with id of "bypass" - jQuery style selector
                '#bypassme': function(element, renderer) {
                    // true = "handled elsewhere, bypass text extraction"
                    return true
                }
            }
            , margins = {
  top: 80,
  bottom: 60,
  left: 40,
  width: 522
 };
  data.push(headers);
        // go through cells
        for (var i=1; i<table.rows.length;i++) {
     
            var tableRow = table.rows[i];
            var rowData = {};
            for (var j=0; j<tableRow.cells.length,j<5 ; j++) {
     
                rowData[ headers[j] ] = tableRow.cells[j].innerHTML; 
            }
            data.push(rowData);
        }       
        return data;
    }
     function callme(){
       var doc = new jsPDF('');

var imgData = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASA....;
doc.addImage(imgData, 'JPEG', 10, 10, 35, 35);
doc.setFontSize(30);
doc.setTextColor(255, 0, 0);
doc.text(80, 20, "Liste des Clients");

doc.setLineWidth(0.5);
doc.line(100, 25, 150, 25);
var header = [1,2,3,4,5];
    var table = tableToJson($('#table').get(0),header, {
    left:80,
    right:10,
    top:500,
    bottom: 50,
    width: 60,
    autoSize:false,
    printHeaders: true
    }); 
    
    doc.setFontSize('10', 'pt', 'letter','true');  
    doc.setTextColor(0,0,0)
$.each(table, function(i, row){
 $.each(row, function(j,cell){
 if (j=="Email" || j==3 || j=="Adresse de Facturation" || j==4){
  doc.cell(1,10,40,20,cell,i); 
 }
 else{
  doc.cell(1,10,40,20,cell,i);
 }
 
 });
});
doc.line(100,100,100,100);
doc.setLineWidth(0.5);
doc.line(20, 25, 160, 25);
doc.text(30,20,"Notes");
doc.save('clients.pdf');
}

and this is the result that I get:
enter link description here
thanks for help

jspdf is a library to create pdf files from html code

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.