showcase.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Html2Pdf</title>
  5. <link rel="stylesheet" type="text/css" href="examples.css">
  6. <style>
  7. </style>
  8. </head>
  9. <body>
  10. <div style='position: absolute; left: 0; top: 0; bottom: 0; overflow: auto; width: 400px'>
  11. <h1>Html2Pdf</h1>
  12. <p>
  13. This demo uses Html2Canvas.js to render HTML. <br />Instead of using an HTML canvas however, a canvas wrapper using jsPDF is substituted. The <em>context2d</em> provided by the wrapper calls native PDF rendering methods.
  14. </p>
  15. <p>A PDF of this page will be inserted into the right margin.</p>
  16. <h2>Colors</h2>
  17. <p>
  18. <span style='color: red'>red</span> <span style='color: rgb(0, 255, 0)'>rgb(0,255,0)</span> <span style='color: rgba(0, 0, 0, .5)'>rgba(0,0,0,.5)</span> <span style='color: #0000FF'>#0000FF</span> <span style='color: #0FF'>#0FF</span>
  19. </p>
  20. <h2>Text Alignment</h2>
  21. <div style='text-align: left'>left</div>
  22. <div style='text-align: center'>center</div>
  23. <div style='text-align: right'>right</div>
  24. <h2>Margins and Padding</h2>
  25. <div style='background-color: red'>
  26. Red
  27. <div style='background-color: green; margin: 1em; padding: 1em;'>
  28. Green
  29. <div style='background-color: blue; margin: 1em'>Blue</div>
  30. </div>
  31. </div>
  32. <h2>Borders</h2>
  33. <div style='border: 1px solid black'>Single</div>
  34. <hr />
  35. <div style='border: 4px double black'>Double</div>
  36. <h2>Font Style</h2>
  37. <div style='font-style: normal'>Normal</div>
  38. <div style='font-style: italic'>Italic</div>
  39. <div style='font-style: oblique'>Oblique</div>
  40. <h2>Lists</h2>
  41. <ul>
  42. <li>apples</li>
  43. <li>oranges</li>
  44. <li>pears</li>
  45. <li>peaches</li>
  46. <li>lemons</li>
  47. <li>limes</li>
  48. </ul>
  49. <h2>Font Size</h2>
  50. <div style='font-size: 10px'>10px</div>
  51. <div style='font-size: 20px'>20px</div>
  52. <div style='font-size: 30px'>30px</div>
  53. <div style='font-size: 20pt'>20pt</div>
  54. <div style='font-size: 1em'>1em</div>
  55. <div style='font-size: 2em'>2em</div>
  56. </div>
  57. <script src='../../dist/jspdf.debug.js'></script>
  58. <script src='../../libs/html2pdf.js'></script>
  59. <script>
  60. var pdf = new jsPDF('p', 'pt', 'letter');
  61. var canvas = pdf.canvas;
  62. canvas.height = 72 * 11;
  63. canvas.width=72 * 8.5;;
  64. // var width = 400;
  65. html2pdf(document.body, pdf, function(pdf) {
  66. var iframe = document.createElement('iframe');
  67. iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
  68. document.body.appendChild(iframe);
  69. iframe.src = pdf.output('datauristring');
  70. //var div = document.createElement('pre');
  71. //div.innerText=pdf.output();
  72. //document.body.appendChild(div);
  73. }
  74. );
  75. </script>
  76. </body>
  77. </html>