locked
Save contents of div as image on server RRS feed

  • Question

  • User230779875 posted

    <br>
    I want to capture the contents inside a div(like text box or asp control) as image on button click in javascript<br>
    Sunday, December 3, 2017 3:36 PM

All replies

  • User347430248 posted

    Hi Ramyayadav,

    you need to use "Canvas2image" to save div as image.

    syntax:

    Canvas2Image.saveAsImage(canvasObj, width, height, type)

    example:

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

    for detailed example please refer link below.

    JS Fiddle live example

    Reference:

    https://github.com/hongru/canvas2image

    Regards

    Deepak

    Monday, December 4, 2017 1:11 AM