html2pdf.js icon indicating copy to clipboard operation
html2pdf.js copied to clipboard

html2pdf Blank Page issue - Chrome

Open suresh-ramasamy002 opened this issue 3 years ago • 5 comments

Hi @eKoopmans, html2pdf fails to detects DOM elements and i was trying to download the pdf file and the pdf has only blank pages. This is happening on latest Chrome Version it seems but not on any other browsers. Please help me out with this

suresh-ramasamy002 avatar Jan 28 '22 11:01 suresh-ramasamy002

Try to remove the Grammarly extension, jsPdf has some issues while generating the PDF when using Grammarly.

rajathegde98 avatar Feb 01 '22 10:02 rajathegde98

Hi, @rajathegde98 any other solutions? I cant tell all of our customers to remove their chrome extensions.

danielgutin avatar Feb 01 '22 20:02 danielgutin

//content is the angular child elem reference (if not, use **document.** methods to access div or class)
        html2canvas(content,{
          allowTaint:true,
          useCORS:true,
          scale:1
        }).then(canvas=>{
         // document.body.appendChild(canvas)
          var width = canvas.width;
          var height = canvas.height;
          var img = canvas.toDataURL("image/png")
          var doc = new jsPDF();
          doc.addImage(img,'PNG',0,0,600,200)
          doc.save()
        })

The above code looks fine. It's working for me, update the hardcoded values(width, height). I am using jsPDF and html2canvas instead. hope this helps you.

rajathegde98 avatar Feb 02 '22 16:02 rajathegde98

In the end, I took the following approach, removed the HTML tag that was injected by Grammarly & restored it after the creation of the PDF. image

danielgutin avatar Feb 02 '22 17:02 danielgutin

@danielgutin thanks daniel, It's working for me but all the contents are present except images.

rajathegde98 avatar Feb 03 '22 07:02 rajathegde98