0

i have a div with id="div1" , i need to convert it into pdf .so i tried to do with JSPf in angular 2.JSpdf is working good , when i tried to do doc.autoTable(col, rows);.but when i want export it do pdf its not working

<div class="container" id="div1">
<table>
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>Centro comercial Moctezuma</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
  
</table>
        <button id="create" (click)="convert()">Create file</button> 
    </div>


 convert(){
      const elementToPrint = document.getElementById('div1');
      console.log('eelementToPrint',elementToPrint); //The html element to become a pdf
      const pdf = new jsPDF('p', 'pt', 'a4');
      pdf.addHTML(elementToPrint, () => {
          doc.save('web.pdf');
      });
}
Vivin Prasannaa
  • 140
  • 2
  • 11

2 Answers2

0

You are referring to a variable that doesn't exist in doc.save()

You should refer to the documentation where it says that addHTML is deprecated and you should use html2pdf library.

http://rawgit.com/MrRio/jsPDF/master/docs/global.html#addHTML

https://github.com/spipu/html2pdf

Dan R.
  • 638
  • 5
  • 13
0

Firstly,

pdf.save('web.pdf');

and also you should keep in mind that this function does not support css, if you decide to use it.

Yevhenii Bahmutskyi
  • 1,561
  • 3
  • 20
  • 38