Search
 
SCRIPT & CODE EXAMPLE
 

HTML

converting HTML table to image

<html>
   <head>
   </head>
   <body>
      <table id="myTable" class="table table-bordered table-striped table-fixed">
         <thead>
            <th>Key Account</th>
            <th>Key Account Code</th>
            <th>Potential Value</th>
            <th>Sales Value</th>
            <th>Penetration %</th>
            <th>Potential (H/M/L)</th>
            <th>Penetration (H/M/L)</th>
         </thead>
         <?php echo "Some data from database here";?>   
      </table>
      <button id="convert">
      Convert to image
      </button>
      <div id="result">
         <!-- Result will appear be here -->
      </div>
      <script type="text/javascript" src="https://github.com/niklasvh/html2canvas/releases/download/0.5.0-alpha1/html2canvas.js"></script>
      <script>
         //convert table to image            
         function convertToImage() {
            var resultDiv = document.getElementById("result");
            html2canvas(document.getElementById("myTable"), {
                onrendered: function(canvas) {
                    var img = canvas.toDataURL("image/png");
                    result.innerHTML = '<a download="test.jpeg" href="'+img+'">test</a>';
                    }
            });
         }        
         //click event
         var convertBtn = document.getElementById("convert");
         convertBtn.addEventListener('click', convertToImage);
      </script>
   </body>
</html>
Comment

PREVIOUS NEXT
Code Example
Html :: coreui margin right 
Html :: click on tr redirect new page 
Html :: html put newline in text with  
Html :: basic html boilerplate 
Html :: how to make a list in html 
Html :: Bootstrap Image Grid (Responsive) 
Html :: html select component 
Html :: boostrap card 
Html :: html article 
Html :: same form two submits 
Html :: menu hamburguer html 
Html :: how to set timeout for a div tag in html 
Html :: how to create seprate flex box for adding items into the box 
Html :: typo3 fluid format html 
Html :: radio buttons in bootstrap 
Html :: how to create js code 
Html :: html syntax 
Html :: Hyperlink to text simple html a tag 
Html :: html partial view 
Html :: html special characters 
Html :: html popup form 
Html :: html flag icons 
Html :: Combining <symbol with <use SVG tags on a HTML page 
Html :: crawler get text, not get html 
Html :: lwc unescaped html 
Html :: login icon html 
Html :: mozilla date input 
Html :: asp.net mvc go to page 
Html :: bootstrap input tagsinput 
Html :: how to do anchor in jupyter notebook markdown 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =