Guest User

Untitled

a guest
Aug 16th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2. <html>
  3. <head>
  4.  
  5.  <script src="http://mrrio.github.io/jsPDF/dist/jspdf.debug.js"></script>
  6.  
  7. </head>
  8. <body>
  9.  
  10. <div id="customers">
  11.     <table id="tab_customers" class="table table-striped">
  12.         <colgroup>
  13.             <col width="20%">
  14.                 <col width="20%">
  15.                     <col width="20%">
  16.                         <col width="20%">
  17.         </colgroup>
  18.         <thead>
  19.             <tr class='warning'>
  20.                 <th>Country</th>
  21.                 <th>Population</th>
  22.                 <th>Date</th>
  23.                 <th>Age</th>
  24.             </tr>
  25.         </thead>
  26.         <tbody>
  27.             <tr>
  28.                 <td>Chinna</td>
  29.                 <td>1,363,480,000</td>
  30.                 <td>March 24, 2014</td>
  31.                 <td>19.1</td>
  32.             </tr>
  33.             <tr>
  34.                 <td>India</td>
  35.                 <td>1,241,900,000</td>
  36.                 <td>March 24, 2014</td>
  37.                 <td>17.4</td>
  38.             </tr>
  39.             <tr>
  40.                 <td>United States</td>
  41.                 <td>317,746,000</td>
  42.                 <td>March 24, 2014</td>
  43.                 <td>4.44</td>
  44.             </tr>
  45.             <tr>
  46.                 <td>Indonesia</td>
  47.                 <td>249,866,000</td>
  48.                 <td>July 1, 2013</td>
  49.                 <td>3.49</td>
  50.             </tr>
  51.             <tr>
  52.                 <td>Brazil</td>
  53.                 <td>201,032,714</td>
  54.                 <td>July 1, 2013</td>
  55.                 <td>2.81</td>
  56.             </tr>
  57.         </tbody>
  58.     </table>
  59. </div>
  60. <button onclick="javascript:demoFromHTML()">PDF</button>
  61.  
  62. </body>
  63. <html>
  64.  
  65.  
  66.  
  67. <script>
  68.  
  69. function demoFromHTML() {
  70.     var pdf = new jsPDF('p', 'pt', 'letter');
  71.     // source can be HTML-formatted string, or a reference
  72.     // to an actual DOM element from which the text will be scraped.
  73.     source = $('#customers')[0];
  74.  
  75.     // we support special element handlers. Register them with jQuery-style
  76.     // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
  77.     // There is no support for any other type of selectors
  78.     // (class, of compound) at this time.
  79.     specialElementHandlers = {
  80.         // element with id of "bypass" - jQuery style selector
  81.         '#bypassme': function (element, renderer) {
  82.             // true = "handled elsewhere, bypass text extraction"
  83.             return true
  84.         }
  85.     };
  86.     margins = {
  87.         top: 80,
  88.         bottom: 60,
  89.         left: 40,
  90.         width: 522
  91.     };
  92.     // all coords and widths are in jsPDF instance's declared units
  93.     // 'inches' in this case
  94.     pdf.fromHTML(
  95.     source, // HTML string or DOM elem ref.
  96.     margins.left, // x coord
  97.     margins.top, { // y coord
  98.         'width': margins.width, // max width of content on PDF
  99.         'elementHandlers': specialElementHandlers
  100.     },
  101.  
  102.     function (dispose) {
  103.         // dispose: object with X, Y of the last line add to the PDF
  104.         //          this allow the insertion of new lines after html
  105.         pdf.save('Test.pdf');
  106.     }, margins);
  107. }
  108. </script>
Advertisement
Add Comment
Please, Sign In to add comment