examples.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. exit;
  3. require_once("../dompdf_config.inc.php");
  4. if ( isset( $_POST["html"] ) ) {
  5. if ( get_magic_quotes_gpc() )
  6. $_POST["html"] = stripslashes($_POST["html"]);
  7. $dompdf = new DOMPDF();
  8. $dompdf->load_html($_POST["html"]);
  9. $dompdf->set_paper($_POST["paper"], $_POST["orientation"]);
  10. $dompdf->render();
  11. $dompdf->stream("dompdf_out.pdf");
  12. exit(0);
  13. }
  14. ?>
  15. <?php include("head.inc"); ?>
  16. <div id="toc">
  17. <h2>On this page:</h2>
  18. <ul>
  19. <?php echo li_arrow() ?><a href="#samples">Samples</a></li>
  20. <?php echo li_arrow() ?><a href="#demo">Demo</a></li>
  21. </ul>
  22. </div>
  23. <a name="samples"> </a>
  24. <h2>Samples</h2>
  25. <p>Below are some sample files. The PDF version is generated on the fly by dompdf. (The source HTML &amp; CSS for
  26. these files is included in the test/ directory of the distribution
  27. package.)</p>
  28. <ul class="samples">
  29. <?php
  30. $test_files = glob("test/*.{html,php}", GLOB_BRACE);
  31. //if dompdf.php runs in virtual server root, dirname does not return empty folder but '/' or '\' (windows).
  32. //This leads to a duplicate separator in unix etc. and an error in Windows. Therefore strip off.
  33. //echo '<li>['.$_SERVER["PHP_SELF"].']</li>';
  34. $dompdf = dirname(dirname($_SERVER["PHP_SELF"]));
  35. //echo '<li>['.$dompdf.']</li>';
  36. if ( $dompdf == '/' || $dompdf == '\\') {
  37. $dompdf = '';
  38. }
  39. //echo '<li>['.$dompdf.']</li>';
  40. $dompdf .= "/dompdf.php?base_path=" . rawurlencode("www/test/");
  41. //echo '<li>['.$dompdf.']</li>';
  42. foreach ( $test_files as $file ) {
  43. $file = basename($file);
  44. $arrow = "images/arrow_0" . rand(1, 6) . ".gif";
  45. echo "<li style=\"list-style-image: url('$arrow');\">\n";
  46. echo $file;
  47. echo " [<a class=\"button\" target=\"blank\" href=\"test/$file\">HTML</a>] [<a class=\"button\" href=\"$dompdf&input_file=" . rawurlencode("$file") . "\">PDF</a>]\n";
  48. echo "</li>\n";
  49. }
  50. ?>
  51. </ul>
  52. <a name="demo"> </a>
  53. <h2>Demo</h2>
  54. <p>Enter your html snippet in the text box below to see it rendered as a
  55. PDF: (Note by default, remote stylesheets, images &amp; are disabled.)</p>
  56. <form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
  57. <div>
  58. <p>Paper size and orientaion:
  59. <select name="paper">
  60. <?php
  61. foreach ( array_keys(CPDF_Adapter::$PAPER_SIZES) as $size )
  62. echo "<option ". ($size == "letter" ? "selected " : "" ) . "value=\"$size\">$size</option>\n";
  63. ?>
  64. </select>
  65. <select name="orientation">
  66. <option value="portrait">portrait</option>
  67. <option value="landscape">landscape</option>
  68. </select>
  69. </p>
  70. <textarea name="html" cols="60" rows="20">
  71. &lt;html&gt;
  72. &lt;head&gt;
  73. &lt;style&gt;
  74. /* Type some style rules here */
  75. &lt;/style&gt;
  76. &lt;/head&gt;
  77. &lt;body&gt;
  78. &lt;!-- Type some HTML here --&gt;
  79. &lt;/body&gt;
  80. &lt;/html&gt;
  81. </textarea>
  82. <div style="text-align: center; margin-top: 1em;">
  83. <input type="submit" name="submit" value="submit"/>
  84. </div>
  85. </div>
  86. </form>
  87. <p style="font-size: 0.65em; text-align: center;">(Note: if you use a KHTML
  88. based browser and are having difficulties loading the sample output, try
  89. saving it to a file first.)</p>
  90. <?php include("foot.inc"); ?>