demo.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. require_once("../dompdf_config.inc.php");
  3. // We check wether the user is accessing the demo locally
  4. $local = array("::1", "127.0.0.1");
  5. $is_local = in_array($_SERVER['REMOTE_ADDR'], $local);
  6. if ( isset( $_POST["html"] ) && $is_local ) {
  7. if ( get_magic_quotes_gpc() )
  8. $_POST["html"] = stripslashes($_POST["html"]);
  9. $dompdf = new DOMPDF();
  10. $dompdf->load_html($_POST["html"]);
  11. $dompdf->set_paper($_POST["paper"], $_POST["orientation"]);
  12. $dompdf->render();
  13. $dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
  14. exit(0);
  15. }
  16. ?>
  17. <?php include("head.inc"); ?>
  18. <a name="demo"> </a>
  19. <h2>Demo</h2>
  20. <?php if ($is_local) { ?>
  21. <p>Enter your html snippet in the text box below to see it rendered as a
  22. PDF: (Note by default, remote stylesheets, images &amp; inline PHP are disabled.)</p>
  23. <form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
  24. <p>Paper size and orientation:
  25. <select name="paper">
  26. <?php
  27. foreach ( array_keys(CPDF_Adapter::$PAPER_SIZES) as $size )
  28. echo "<option ". ($size == "letter" ? "selected " : "" ) . "value=\"$size\">$size</option>\n";
  29. ?>
  30. </select>
  31. <select name="orientation">
  32. <option value="portrait">portrait</option>
  33. <option value="landscape">landscape</option>
  34. </select>
  35. </p>
  36. <textarea name="html" cols="60" rows="20">
  37. &lt;html&gt;
  38. &lt;head&gt;
  39. &lt;style&gt;
  40. /* Type some style rules here */
  41. &lt;/style&gt;
  42. &lt;/head&gt;
  43. &lt;body&gt;
  44. &lt;!-- Type some HTML here --&gt;
  45. &lt;/body&gt;
  46. &lt;/html&gt;
  47. </textarea>
  48. <div style="text-align: center; margin-top: 1em;">
  49. <button type="submit">Download</button>
  50. </div>
  51. </form>
  52. <p style="font-size: 0.65em; text-align: center;">(Note: if you use a KHTML
  53. based browser and are having difficulties loading the sample output, try
  54. saving it to a file first.)</p>
  55. <?php } else { ?>
  56. <p style="color: red;">
  57. User input has been disabled for remote connections.
  58. </p>
  59. <?php } ?>
  60. <?php include("foot.inc"); ?>