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

Cannot read property 'canvas' of undefined

Open christopheSeeka opened this issue 5 years ago • 14 comments

Hello, im trying a simple test:

this is in my header:

this is my code :

      var element = document.getElementById('my-table');
      var worker = html2pdf();
      var worker = html2pdf().from(element).save();

And constantly get "Cannot read property 'canvas' of undefined

Any idea ?

christopheSeeka avatar Jul 02 '19 13:07 christopheSeeka

im having the same issue any luck?

Slader10 avatar Sep 18 '19 14:09 Slader10

Same issue hare mate. Any luck? How did you solve it?

dimitrianoudi avatar Nov 01 '19 20:11 dimitrianoudi

Found out that it's working on double click. It outputs an error "Uncaught in promise" then downloads the pdf. Weird.

dimitrianoudi avatar Nov 04 '19 00:11 dimitrianoudi

why is this closed? npm install this library and it gives this error. Seems to be an issue

northkode avatar Aug 15 '20 19:08 northkode

Got the same issue

mtom55 avatar Aug 20 '20 00:08 mtom55

So i found out that npm install does not install the right stuff... i had to use the cdn version and it works. So something is messed with the dependency tree of the npm published module

northkode avatar Aug 20 '20 02:08 northkode

I found the promise API worked even on the npm version const element = document.getElementsByTagName('body')[0]; html2pdf().set({}).from(element).save();

mtom55 avatar Aug 20 '20 02:08 mtom55

I am getting the same error. I am using:

Euler-JS avatar Apr 29 '22 09:04 Euler-JS

Any solution to this issue?

nadeefit6 avatar Jul 11 '22 04:07 nadeefit6

Any solutions yet?

mickbut-ler avatar Jul 22 '22 13:07 mickbut-ler

I had this exact issue. This working fiddle got me started: https://jsfiddle.net/eKoopmans/z1rupL4c/, using the dependencies copied literally as local deps/scripts. This link came from the README under Known issues/rendering. Also, I had an extra jspdf dependency from previous fiddling. After including the 2 scripts and removing other jspdf script tag, it works as advertised.

saltermitch avatar Oct 24 '22 16:10 saltermitch

this work for me!! define the next function

 function addScript(url) {
     var script = document.createElement('script');
     script.type = 'application/javascript';
     script.src = url;
     document.head.appendChild(script);
 }

and then when your document is ready call it like that addScript('https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js');

AndresThomas avatar Nov 30 '22 17:11 AndresThomas