Search code examples
javascriptjspdfhtml2canvashtml2pdf

How can I fix the "blank page" issue in html2pdf.js?


I'm trying to convert the HTML document to PDF using html2pdf.js, but as a result I get a pdf with a blank first page and the last page of the document being half cropped. How such issue could be fixed ? Code:

document.querySelector('.save-pdf').addEventListener('click', function () {
   const elementToPrint = document.getElementById('content');

   const opt = {
      margin:       0,
      filename:     'contract.pdf',
      image:        { type: 'png' },
      html2canvas:  { scale: 2 },
      jsPDF:        { unit: 'in', format: 'letter', orientation: 'p' }
   };


   html2pdf(elementToPrint, opt);
});

Solution

  • The problem solved by switching the version of "html2canvas" library from "rc 5" to "alpha 12".