Preview and Download Html2Canvas

Here is the code for converting html into canvas.

When we click on Preview button canvas will be show and click on Download canvas will be save in .png format.


<!DOCTYPE html>
<html>
<head>

<!-- include jquery.min.js and html2canvas.js -->
  <script src="jquery/3.1.1/jquery.min.js"></script>
  <script src="jquery/html2canvas.js"></script>

<style>
  #previewBody{
    background-color: #9E9E9E;
    color: #fff;
    padding: 5px 0px 27px 30px;
    width: 46%;
    margin-bottom: 15px;
}
input#PreviewImage {
    margin-bottom: 15px;
}
</style>

<script>
    $(document).ready(function(){
    var getCanvas;
    function callCanvas(){
    html2canvas($("#previewBody"), {
    onrendered: function(canvas) {
    $(".preview_Canvas").html(canvas);
    getCanvas = canvas;
    }
  });
}
   $("#PreviewImage").on('click', function () {
    callCanvas()
    });
   $("#downloadimage").on('click', function () {
      var imgageData = getCanvas.toDataURL("image/png");    
    // Now browser starts downloading it instead of just showing it
    var newData = imgageData.replace(/^data:image\/png/, "data:application/octet-stream");
    $("#downloadimage").attr("download", "your_pic_name.png").attr("href", newData);
  });
});
</script>
</head>
<body>
<div id="previewBody">
  <h2>CANVAS Example</h2>
  <p>Click on preview will show canvas </p>
  <p>Click on download will download the canvas in .png format</p>
   </div>
    
        <input id="PreviewImage" type="button" value="Preview"/>
        <a id="downloadimage" href="#">Download</a>
        <div class="preview_Canvas">
        </div>
</body>
</html>

Share on Google+Share on FacebookTweet about this on TwitterEmail this to someone
 
 
 

Grouping of select box options through javascript

Your select box 

<select>
<option value="aaa">aaa</option>
<option value="bbb">bbb</option>
<option value="ccc">ccc</option>
<option value="ddd">ddd</option>
<option value="eee">eee</option>
<option value="fff">fff</option>
</select>
<script type="text/javascript">
$(function () {
    var $cont = $('select');
   
    $('select option').each(function () {
        if ($(this).text().indexOf('aaa') === 0 || $(this).text().indexOf('ddd') === 0) {
            $('<optGroup/>').attr('label', $(this).text()).appendTo($cont);
            $(this).remove();
        } else {
            $cont.find('optGroup').last().append($(this));
            $(this).text($(this).text());
        }
    });
    });

</script>
Share on Google+Share on FacebookTweet about this on TwitterEmail this to someone
 

How to apply border radius on table row

<table>
<tr class="head">
	<td>Title 1</td>
	<td>Title 2</td>
</tr>
<tr>
	<td>Col 1</td>
	<td>Col 2</td>
</tr>
<tr>
	<td>Col 1</td>
	<td>Col 2</td>
</tr>
<tr>
	<td>Col 1</td>
	<td>Col 2</td>
</tr>
</table>

<style>
table{
	width:100%;
	border-collapse: collapse;
}
tr td{
	padding:10px;	
}
tr.head td{
	background-color:#D83125;
	color:#fff;
}
tr.head td:first-child{
	 border-top-left-radius: 10px;
	 border-bottom-left-radius: 10px;
}
tr.head td:last-child{
	 border-top-right-radius: 10px;
	 border-bottom-right-radius: 10px;
}
</style>


Share on Google+Share on FacebookTweet about this on TwitterEmail this to someone