I created html table and tried to generate pdf using jsPDF.
I have used following code:
var pdf = new jsPDF('p','pt','a4');
pdf.addHTML(document.getElementById('pdfTable'),function() {
console.log('pdf generated');
});
pdf.save('pdfTable.pdf');
I am getting blank pdf file. Am I doing anything wrong?
Here is a plunker for this.
Working demo of jsPDF with addHTML function.
Made working plunker for this:
Update:
I have updated the plunker and made it work with addHTML() function:
var pdf = new jsPDF('p','pt','a4');
//var source = document.getElementById('table-container').innerHTML;
console.log(document.getElementById('table-container'));
var margins = {
top: 25,
bottom: 60,
left: 20,
width: 522
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.text(20, 20, 'Hello world.');
pdf.addHTML(document.body, margins.top, margins.left, {}, function() {
pdf.save('test.pdf');
});
You can see plunker for more details.
Change this in app.js:
pdf.addHTML(document.getElementById('pdfTable'),function() {
});
pdf.save('pdfTable.pdf');
for this one:
pdf.addHTML(document.getElementById('pdfTable'),function() {
pdf.save('pdfTable.pdf');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With