Hi, I have been trying to get the image URL for my div using html2canvas. But it seems to be not working at all. I have tested with browsers like chrome, mozilla firefox, edge.
Here below is my sample code which i am using to get the image data URL. But i am surprised to see that i am not getting image data.
var printDiv = function() {
var target = $('#drawing-area');
var img;
html2canvas(target, {
onrendered: function(canvas)
{
img = canvas.toDataURL();
alert(img);
}
});
return img;
}
Same here, onrendered does not get called.
Update - it didn't get rendered because I had an error in a different JS library (was jsPDF in my case). Once I removed that it worked.
In 0.5.0 version it is replaced by .then (Promise.js), see example:
html2canvas(document.body).then(function(canvas) {
document.body.appendChild(canvas);
});
Always read the README file.
if you are using 0.4.1 version then see webbrowser console, maybe you find javascript issues in other script.
Good luck!
I am using html2canvas in my site. It was working fine till we changed the site images and scripts to be loaded from CDN server. Print is not working now. Is that because of the same origin problem of the images and can it be corrected by adding the proxy handler for the site. please check and revert.
Thanks @OmriAharon that solved it for me..
@HMubaireek @OmriAharon what was the issue with jsPDF? It's not getting into the onrendered for me at all, and I have no errors anywhere.
Hi, I have same issue with onrendered. I dont see any error in any of the js file. what could be wrong?
Thanks!
Because this is pretty high when you Google for this issue: jspdf.debug.js contains their own version of html2canvas which is incompatible with jspdf(I don't know why either, just accept it). So if you load html2canvas AFTER loading jspdf you should be fine and get no randomly missed onrendered calls.
Most helpful comment
In 0.5.0 version it is replaced by .then (Promise.js), see example:
Always read the README file.
if you are using 0.4.1 version then see webbrowser console, maybe you find javascript issues in other script.
Good luck!