Translate

Showing posts with label sample code for convert html to pdf using js pdf. Show all posts
Showing posts with label sample code for convert html to pdf using js pdf. Show all posts

Friday, 9 June 2017

div to pdf using jsPDF

<html>
   <head>
      <title>Demo Pdf Print </title>
   </head>
   <body>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
      <button id="btnPrint">generate PDF</button>
      <div id="divExportToPDF">
         <table style="width:100%">,
            <tr>
               <th>Firstname</th>
               <th>Lastname</th>
               <th>Age</th>
            </tr>
            <tr>
               <td>Jill</td>
               <td>Smith</td>
               <td>50</td>
            </tr>
            <tr>
               <td>Eve</td>
               <td>Jackson</td>
               <td>94</td>
            </tr>
         </table>
      </div>
      <script type="text/javascript">
          $(document).ready(function () {
              $('#btnPrint').click(function () {
                  var pdf = new jsPDF('p', 'pt', 'a4');
                  pdf.addHTML(document.body, function () {
                      pdf.save('SamplePDF.pdf');
                  });
              });
          });
      </script>
   </body>
</html>