JsPDF downloading blank pdf


I'm using jsPDF to generate a pdf from the current HTML, the code works fine if I paste it on the console and downloads a PDF with the current HTML, but when I put it on a JS file it downloads a blank PDF:

This is the code:

  function descargar_pdf(){
      var pdf = new jsPDF();
      pdf.addHTML(document.body,function() {});

The function is called from a button:

<button class="descargar_pdf" id="ignorePDF" onclick="descargar_pdf();"> Descarga tu estado de cuenta</button>

Best Solution

The second argument in the addHTML function is a callback function which gets called after the HTML is rendered.

pdf.addHTML(document.body, function() {
Related Question