Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert div into image data using jquery


I have a html page. In which I have a button, whenever I click this button it should convert the entire html page into data image. I achieved this by using html2canvas as follow:

html2canvas([document.getElementById('form1')], {
        onrendered: function (canvas) {
            var imageData = canvas.toDataURL('image/jpeg',1.0); 
     }
    });

It is giving me the image data but without checkboxes and radio buttons. So is there any alternative to convert the html page to image data using jquery or javascript??
If there, please help me to come out from this problem.
Thank you in advance.

like image 513
Manoj Nayak Avatar asked Oct 21 '22 10:10

Manoj Nayak


2 Answers

You're only converting the part in form1

document.getElementById('form1')

Try using

html2canvas(document.body, {
    onrendered: function (canvas) {
        var imageData = canvas.toDataURL('image/png',1.0); 
 }
});
like image 88
testydonkey Avatar answered Oct 23 '22 00:10

testydonkey


html2canvas has issues with rendering radiobuttons and checkboxes, as described in another question @ https://stackoverflow.com/questions/19704618/how-to-display-checkbox-with-html2canvas. The solution given there is to replace those radiobuttons and checkboxes with images and then capturing the page.

The solution provided in the question above does not work as is if I read it correctly, but should help you along to writing a working fix.

like image 44
Sander van Leeuwen Avatar answered Oct 23 '22 00:10

Sander van Leeuwen