Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsPDF downloading blank pdf

Tags:

jspdf

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:

<script>
  function descargar_pdf(){
      var pdf = new jsPDF();
      pdf.addHTML(document.body,function() {});
      pdf.save('Estadodecuenta.pdf');
  };
</script>

The function is called from a button:

<button class="descargar_pdf" id="ignorePDF" onclick="descargar_pdf();"> Descarga tu estado de cuenta</button>
like image 735
Victor Castillo Torres Avatar asked Dec 19 '22 06:12

Victor Castillo Torres


1 Answers

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

pdf.addHTML(document.body, function() {
    pdf.save('*.pdf');
});
like image 63
azium Avatar answered Dec 21 '22 19:12

azium