Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

173 lines
5.3KB

  1. <?php
  2. $excl = array('HTML-CSS', 'DIRECTW', 'TABLES', 'IMAGES-CORE',
  3. 'IMAGES-BMP', 'IMAGES-WMF', 'TABLES-ADVANCED-BORDERS', 'COLUMNS', 'TOC', 'INDEX', 'BOOKMARKS', 'BARCODES', 'FORMS',
  4. 'WATERMARK', 'CJK-FONTS', 'INDIC', 'ANNOTATIONS', 'BACKGROUNDS', 'CSS-FLOAT', 'CSS-IMAGE-FLOAT', 'CSS-POSITION',
  5. 'CSS-PAGE', 'BORDER-RADIUS', 'HYPHENATION', 'ENCRYPTION', 'IMPORTS', 'PROGRESS-BAR', 'OTL');
  6. // *DIRECTW* = Write, WriteText, WriteCell, Text, Shaded_box, AutosizeText
  7. // IMAGES-CORE = [PNG, GIF, and JPG] NB background-images and watermark images
  8. // Excluding 'HTML-CSS' will also exclude: 'TABLES', 'LISTS', 'TABLES-ADVANCED-BORDERS', 'FORMS', 'BACKGROUNDS', 'CSS-FLOAT', 'CSS-IMAGE-FLOAT', 'CSS-POSITION', 'CSS-PAGE', 'BORDER-RADIUS'
  9. // Text is marked in mpdf_source.php with e.g. :
  10. /* -- TABLES-ADVANCED-BORDERS -- */
  11. /* -- END TABLES-ADVANCED-BORDERS -- */
  12. // *TABLES-ADVANCED-BORDERS*
  13. if (!isset($_POST['generate']) || $_POST['generate'] != 'generate') {
  14. if (!file_exists('mpdf_source.php')) {
  15. die("ERROR - Could not find mpdf_source.php file in current directory. Please rename mpdf.php as mpdf_source.php");
  16. }
  17. echo '<html>
  18. <head>
  19. <script language=javascript>
  20. checked=false;
  21. function checkedAll (frm1) {
  22. var aa= document.getElementById("frm1");
  23. if (checked == false)
  24. {
  25. checked = true
  26. }
  27. else
  28. {
  29. checked = false
  30. }
  31. for (var i =0; i < aa.elements.length; i++)
  32. {
  33. aa.elements[i].checked = checked;
  34. }
  35. }
  36. </script>
  37. </head>
  38. <body>
  39. <p><span style="color:red; font-weight: bold;">WARNING</span>: This utility will OVERWRITE mpdf.php file in the current directory.</p>
  40. <p>Select the functions you wish to INCLUDE in your mpdf.php program. When you click generate, a new mpdf.php file will be written to the current directory.</p>
  41. <div><b>Notes</b>
  42. <ul>
  43. <li>HTML-CSS is required for many of the other functions to work including: Tables, Lists, Backgrounds, Forms, Border-radius and all other CSS</li>
  44. <li>DIRECTW includes the functions to Write directly to the PDF file e.g. Write, WriteText, WriteCell, Text, Shaded_box, AutosizeText</li>
  45. <li>You must include either HTML-CSS or DIRECTW</li>
  46. <li>JPG, PNG and JPG images are supported with IMAGES-CORE</li>
  47. <li>For WMF Images, you must include both IMAGES-CORE and IMAGES-WMF</li>
  48. <li>IMAGES-CORE are required for BACKGROUNDS (IMAGES) or WATERMARKS to work</li>
  49. <li>OTL (OpenType Layout) is required for RTL (right-to-left) scripts to work</li>
  50. </ul>
  51. </div>
  52. <input type="checkbox" name="checkall" onclick="checkedAll(frm1);"> <i>Select/Unselect All</i><br /><br />
  53. <form id="frm1" action="compress.php" method="POST">
  54. ';
  55. foreach ($excl AS $k => $ex) {
  56. echo '<input type="checkbox" value="1" name="inc[' . $ex . ']"';
  57. if ($k == 0 || ($k > 1 && $k < 5)) {
  58. echo ' checked="checked"';
  59. }
  60. echo ' /> ' . $ex . '<br />';
  61. }
  62. echo '<br />
  63. <input type="submit" name="generate" value="generate" />
  64. </form>
  65. </body>
  66. </html>';
  67. exit;
  68. }
  69. $inc = $_POST['inc'];
  70. if (is_array($inc) && count($inc) > 0) {
  71. foreach ($inc AS $i => $v) {
  72. $key = array_search($i, $excl);
  73. unset($excl[$key]);
  74. }
  75. }
  76. if (!defined('PHP_VERSION_ID')) {
  77. $version = explode('.', PHP_VERSION);
  78. define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
  79. }
  80. if (PHP_VERSION_ID < 50300) {
  81. $mqr = @get_magic_quotes_runtime();
  82. } else {
  83. $mqr = 0;
  84. }
  85. if ($mqr) {
  86. set_magic_quotes_runtime(0);
  87. }
  88. $l = file('mpdf_source.php');
  89. if (!count($l)) {
  90. die("ERROR - Could not find mpdf_source.php file in current directory");
  91. }
  92. $exclflags = array();
  93. $x = '';
  94. // Excluding 'HTML-CSS' will also exclude: 'TABLES', 'LISTS', 'TABLES-ADVANCED-BORDERS', 'HTMLHEADERS-FOOTERS', 'FORMS', 'BACKGROUNDS', 'CSS-FLOAT', 'CSS-IMAGE-FLOAT', 'CSS-POSITION', 'CSS-PAGE', 'BORDER-RADIUS'
  95. if (isset($excl[0]) && $excl[0] == 'HTML-CSS') {
  96. $excl[] = 'TABLES';
  97. $excl[] = 'TABLES-ADVANCED-BORDERS';
  98. $excl[] = 'FORMS';
  99. $excl[] = 'BACKGROUNDS';
  100. $excl[] = 'CSS-FLOAT';
  101. $excl[] = 'CSS-IMAGE-FLOAT';
  102. $excl[] = 'CSS-POSITION';
  103. $excl[] = 'CSS-PAGE';
  104. $excl[] = 'BORDER-RADIUS';
  105. }
  106. $excl = array_unique($excl);
  107. foreach ($l AS $k => $ln) {
  108. $exclude = false;
  109. // *XXXXX*
  110. preg_match_all("/\/\/ \*([A-Za-z\-]+)\*/", $ln, $m);
  111. foreach ($m[1] AS $mm) {
  112. if (in_array($mm, $excl)) {
  113. $exclude = true;
  114. }
  115. }
  116. /* -- XXXXX -- */
  117. preg_match_all("/\/\*-- ([A-Za-z\-]+) --\*\//", $ln, $m);
  118. foreach ($m[1] AS $mm) {
  119. if (in_array($mm, $excl)) {
  120. $exclflags[$mm] = true;
  121. }
  122. $exclude = true;
  123. }
  124. $exclflags = array_unique($exclflags);
  125. /* -- END XXXX -- */
  126. preg_match_all("/\/\*-- END ([A-Za-z\-]+) --\*\//", $ln, $m);
  127. foreach ($m[1] AS $mm) {
  128. if (in_array($mm, $excl)) {
  129. unset($exclflags[$mm]);
  130. }
  131. $exclude = true;
  132. }
  133. if (count($exclflags) == 0 && !$exclude) {
  134. $x .= $ln;
  135. }
  136. }
  137. // mPDF 5.0
  138. if (function_exists('file_put_contents')) {
  139. $check = file_put_contents('mpdf.php', $x);
  140. } else {
  141. $f = fopen('mpdf.php', 'w');
  142. $check = fwrite($f, $x);
  143. fclose($f);
  144. }
  145. if (!$check) {
  146. die("ERROR - Could not write to mpdf.php file. Are permissions correctly set?");
  147. }
  148. echo '<p><b>mPDF file generated successfully!</b></p>';
  149. echo '<div>mPDF file size ' . number_format((strlen($x) / 1024)) . ' kB</div>';
  150. unset($l);
  151. unset($x);
  152. include('mpdf.php');
  153. $mpdf = new mPDF();
  154. echo '<div>Memory usage on loading mPDF class ' . number_format((memory_get_usage(true) / (1024 * 1024)), 2) . ' MB</div>';
  155. exit;