Used in AngularJS throws Cannot read property 'canvas' of undefined
Uncaught TypeError: Cannot read property 'canvas' of undefined PNG.load._this @ jspdf.debug.js:15637 (anonymous function) @ jspdf.debug.js:15761
version 1.0.272 works for me
The js code still works and runs for 1.0.272 but when you F12 in chrome or IE11 you see there seems to be some issue initializing this reported to console. I think it is only when using in AngularJs.
I am getting exactly the same error, when using EmberJS (Ember-cli). The app just won't start.
v1.0.272 works.
*Edit: I just saw, that this error is also thrown in the basic.html sample in this repository.
I fixed my jspdf.debug.js by doing the following:
First I deleted lines 16868-16982.
Then I enclosed lines 15761-16205 with a try catch-handler:
try{
// here lines 15761-16205
}
catch(err){
console.log('That error occured again.');
}
Now at least my EmberJS-application started up again.
The problem is this line: if (!canvas)
It should be (typeof canvas !== 'object')
I don't think that this is the problem, because the exception is caused by pdf being null/undefined.
html2pdf = function(html,pdf,callback) {
var canvas = pdf.canvas; // pdf here is ===null or ===undefined. Exception is thrown here...
if (!canvas) {
alert('jsPDF canvas plugin not installed');
return;
}
canvas.pdf = pdf;
// other stuff
}
Yes. That's true. My local source file was off by 1 line...
Can you include a stack trace?
See opening post:
PNG.load._this @ jspdf.debug.js:15637 (anonymous function) @ jspdf.debug.js:15761
This is the reason why I enclosed this anonymous function with a try catch block.
This fixes it: function html2pdf (html,pdf,callback){...}
instead of
html2pdf = function(html,pdf,callback)
And the file in lines 16869-16983 should probably not be included in jspdf.debug.js at all. This is an dependency definition file that used require.js and should be optional. I put if (typeof require === 'object') around that block.
Thanks Flamenco. I will test that out.
see https://github.com/MrRio/jsPDF/pull/529 for fix
Hi, will this fix be embedded in the next release ? Thanks.
pls release to bower as soon as possible
bower please
Hey, this fix causes errors in other plugins, such as summernote and switchery. TypeError: element.summernote is not a function at activate. Any ideas?
This isn't in bower yet?