examples.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. require_once "../dompdf_config.inc.php";
  3. //if dompdf.php runs in virtual server root, dirname does not return empty folder but '/' or '\' (windows).
  4. //This leads to a duplicate separator in unix etc. and an error in Windows. Therefore strip off.
  5. $dompdf = dirname(dirname($_SERVER["PHP_SELF"]));
  6. if ( $dompdf == '/' || $dompdf == '\\') {
  7. $dompdf = '';
  8. }
  9. $dompdf .= "/dompdf.php?base_path=" . rawurlencode("www/test/");
  10. include "head.inc";
  11. ?>
  12. <script type="text/javascript">
  13. function resizePreview(){
  14. var preview = $("#preview");
  15. preview.height($(window).height() - preview.offset().top - 2);
  16. }
  17. function getPath(hash) {
  18. var file, type;
  19. var parts = hash.split(/,/);
  20. file = parts[0];
  21. if (parts.length == 2) {
  22. type = parts[1];
  23. }
  24. switch(type) {
  25. default:
  26. case "html":
  27. return "test/"+file;
  28. case "pdf":
  29. return "<?php echo $dompdf; ?>&options[Attachment]=0&input_file="+file+"#toolbar=0&view=FitH&statusbar=0&messages=0&navpanes=0";
  30. }
  31. }
  32. function setHash(hash) {
  33. location.hash = "#"+hash;
  34. }
  35. $(function(){
  36. var preview = $("#preview");
  37. resizePreview();
  38. $(window).scroll(function() {
  39. var scrollTop = Math.min($(this).scrollTop(), preview.height()+preview.parent().offset().top) - 2;
  40. preview.css("margin-top", scrollTop + "px");
  41. });
  42. $(window).resize(resizePreview);
  43. var hash = location.hash;
  44. var type = "html";
  45. if (hash) {
  46. hash = hash.substr(1);
  47. preview.attr("src", getPath(hash));
  48. }
  49. });
  50. </script>
  51. <iframe id="preview" name="preview" src="about:blank" frameborder="0" marginheight="0" marginwidth="0"></iframe>
  52. <a name="samples"> </a>
  53. <h2>Samples</h2>
  54. <p>Below are some sample files. The PDF version is generated on the fly by dompdf. (The source HTML &amp; CSS for
  55. these files is included in the test/ directory of the distribution
  56. package.)</p>
  57. <?php
  58. $extensions = array("html");
  59. if ( DOMPDF_ENABLE_PHP ) {
  60. $extensions[] = "php";
  61. }
  62. $test_files = glob("test/*.{".implode(",", $extensions)."}", GLOB_BRACE);
  63. $sections = array(
  64. "print" => array(),
  65. "css" => array(),
  66. "dom" => array(),
  67. "image" => array(),
  68. "page" => array(),
  69. "encoding" => array(),
  70. "script" => array(),
  71. "quirks" => array(),
  72. "other" => array(),
  73. );
  74. foreach ( $test_files as $file ) {
  75. preg_match("@[\\/](([^_]+)_?(.*))\.(".implode("|", $extensions).")$@i", $file, $matches);
  76. $prefix = $matches[2];
  77. if ( array_key_exists($prefix, $sections) ) {
  78. $sections[$prefix][] = array($file, $matches[3]);
  79. }
  80. else {
  81. $sections["other"][] = array($file, $matches[1]);
  82. }
  83. }
  84. foreach ( $sections as $section => $files ) {
  85. echo "<h3>$section</h3>";
  86. echo "<ul class=\"samples\">";
  87. foreach ( $files as $file ) {
  88. $filename = basename($file[0]);
  89. $title = $file[1];
  90. $arrow = "images/arrow_0" . rand(1, 6) . ".gif";
  91. echo "<li style=\"list-style-image: url('$arrow');\">\n";
  92. echo "
  93. [<a class=\"button\" target=\"preview\" onclick=\"setHash('$filename,html')\" href=\"test/$filename\">HTML</a>]
  94. [<a class=\"button\" target=\"preview\" onclick=\"setHash('$filename,pdf')\" href=\"$dompdf&amp;options[Attachment]=0&amp;input_file=" . rawurlencode($filename) . "#toolbar=0&amp;view=FitH&amp;statusbar=0&amp;messages=0&amp;navpanes=0\">PDF</a>] ";
  95. echo $title;
  96. echo "</li>\n";
  97. }
  98. echo "</ul>";
  99. }
  100. include "foot.inc";