HTML table to pdf using javascript
I created an application to load html table to pdf using javascript which I used jsPDF . The app works fine, but the problem is the table is not correct. The table width as well as the header is incorrectly assigned. I am using angularjs to create a table.
Can someone please give me some suggestion for this issue.
JSFiddle
function demoFromHTML() {
var pdf = new jsPDF('p', 'pt', 'letter');
source = $('#customers')[0];
specialElementHandlers = {
'#bypassme': function (element, renderer) {
return true
}
};
margins = {
top: 4,
bottom: 4,
left: 4,
width: 522
};
pdf.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, { // y coord
'width': margins.width, // max width of content on PDF
'elementHandlers': specialElementHandlers
},
function (dispose) {
pdf.save('Test.pdf');
}, margins);
}
+3
Alex man
source
to share
1 answer
I think you need to do it manually now ( fiddle ):
function demoFromHTML() {
var pdf = new jsPDF('p', 'pt', 'letter');
pdf.cellInitialize();
pdf.setFontSize(10);
$.each( $('#customers tr'), function (i, row){
$.each( $(row).find("td, th"), function(j, cell){
var txt = $(cell).text().trim() || " ";
var width = (j==4) ? 40 : 70; //make 4th column smaller
pdf.cell(10, 50, width, 30, txt, i);
});
});
pdf.save('sample-file.pdf');
}
+3
mb21
source
to share