最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - convert div into image data using jquery - Stack Overflow

programmeradmin3浏览0评论


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 e out from this problem.
Thank you in advance.


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 e out from this problem.
Thank you in advance.

Share Improve this question asked Apr 10, 2014 at 9:49 Manoj NayakManoj Nayak 2,5099 gold badges33 silver badges56 bronze badges 1
  • Please put your html also some part or jsfiddle – Just code Commented Apr 10, 2014 at 9:52
Add a ment  | 

2 Answers 2

Reset to default 2

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); 
 }
});

html2canvas has issues with rendering radiobuttons and checkboxes, as described in another question @ https://stackoverflow./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.

发布评论

评论列表(0)

  1. 暂无评论