Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsPDF: addHTML method not working

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.

like image 593
vinesh Avatar asked Aug 27 '26 14:08

vinesh


2 Answers

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.

like image 90
Aks Avatar answered Aug 30 '26 03:08

Aks


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');
});
like image 41
Morcilla de Arroz Avatar answered Aug 30 '26 04:08

Morcilla de Arroz