Surya Verma
Surya Verma

Reputation: 61

Downloading a html div content in form of an image

I am displaying a table with some data in my jsp. I want to add a download button on top of it , clicking on which will download the whole table in the form of an image. Please help me with this implementation.

Upvotes: 0

Views: 859

Answers (1)

Animesh
Animesh

Reputation: 1033

$(function() { 
$("#btnSave").click(function() { 
    html2canvas($("#widget"), {
        onrendered: function(canvas) {
            theCanvas = canvas;
            document.body.appendChild(canvas);

            // Convert and download as image 
            Canvas2Image.saveAsPNG(canvas); 
            $("#img-out").append(canvas);
            // Clean up 
            //document.body.removeChild(canvas);
        }
    });
});

});

check out this fiddle Demo

Click on Save PNG right click to save image as option and your good to go.

Upvotes: 1

Related Questions