0

I am trying to generate a PDF that features a screenshot of my wrapper element, using jsPDF and html2canvas. See code below:

function printMe() {

html2canvas(document.querySelector("#wrapper")).then(canvas => {
    var dataURL = canvas.toDataURL();   
    var doc = new jsPDF();
    doc.addImage(dataURL, 'PNG', 20, 20);
    doc.save(“test.pdf");
});

}

I receive a security error from toDataURL:

“Unhandled Promise Rejection: SecurityError: The operation is insecure.”

How can I either fix this error or generate a PDF with this screenshot another way? Or, is there a way I could simply force the screenshot to download?

  • Yes only way is "on user request" procedure it require click or right click . No way to do it from code . Can you image scenario : You go to some web page and than your hard disk is full... funny but this is one of most important security aspect for web platform ! – Nikola Lukic Jul 25 '18 at 21:42
  • Possible duplicate of [Image On HTML Canvas Can't Be Downloaded](https://stackoverflow.com/questions/37878264/image-on-html-canvas-cant-be-downloaded) – Nikola Lukic Jul 25 '18 at 21:43

0 Answers0