How To Convert An HTML Element Or Document Into Image ?

How to convert an HTML element or document into image ?

In this article, I will be able to show you ways to convert Html div to a picture using JQuery. Here, I'm generating an HTML div element on the client-side to image png using the html2canvas.js library.

HTML5 has some excellent features; you'll draw charts using canvas tag later you'll reserve it as image png or JPEG format.

To begin, download the latest jQuery library and import it into the online page, we'd like another js library Html2canvas.js, for both I referred cdn, when the user clicks the convert to image button, the div element gets an image printed on canvas then downloaded to the local drive as picture using client-side jQuery.

Below are the example to convert div or Html section into image:-

<!DOCTYPE html> 

        How to convert an HTML element 
        or document into image ? 
    <script src="" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
     <script src=""></script>
                background-color: #F0F0F1; 
                color: #00cc65; width: 500px;padding-left: 25px; 
                padding-top: 10px;
                .heading{color: #3e4b51;}
                #html-content-holder p{color: #3e4b51;}

    <h2 style="color:green"> 
    <h2 style="color:purple"> 
        Convert div to image 
    <div id="html-content-holder" class="main-content"> 
        <h3 class="heading"> 
            ABOUT US 
            Website Design and mobile application development company in coimbatore, India. We have more than years of experience in the IT Services with more than 400 clients. Services we provide website design, web development, Business application development, Facebook marketing, Digital marketing, Mobile Application Development and SEO services

    <input id="btn-Preview-Image" type="button"
                value="Preview" /> 
    <a id="btn-Convert-Html2Image" href="#"> 

    <h3>Preview :</h3> 
    <div id="previewImage"></div> 
        $(document).ready(function() { 
            var element = $("#html-content-holder"); 
            var getCanvas; 

            $("#btn-Preview-Image").on('click', function() { 
                html2canvas(element, { 
                    onrendered: function(canvas) { 
                        getCanvas = canvas; 

            $("#btn-Convert-Html2Image").on('click', function() { 
                var imgageData = 
                var newData = imgageData.replace( 
                /^data:image\/png/, "data:application/octet-stream"); 
                "download", "convertedimage.png").attr( 
                "href", newData); 


Related Posts
Security Testing Company India

The major concerns of an application developer and the client today are software security. Security

What Is The Difference Between Web Design & Web Development

In this article, we are going to discuss the difference between Web Designing and Web

How to optimize OpenCart website ?

Ways to Speed up OpenCart website  There are several ways to Optimize OpenCart website that

Tips To Hire A Web Development Company

Given the pace of technological advancements and highly-competitive business landscape, having a dig

Get free quote for

HTML element Convert into Image

Div Convert into an image using Javascript

document into image

Contact us