compress.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. $excl = array( 'TABLES', 'LISTS', 'IMAGES-CORE',
  3. 'IMAGES-WMF', 'TABLES-ADVANCED-BORDERS', 'UNICODE-FONTS', 'HTMLHEADERS-FOOTERS', 'COLUMNS', 'TOC', 'INDEX', 'BOOKMARKS', 'BARCODES', 'FORMS', 'WATERMARK', 'RTL', 'INDIC', 'CJK', 'ANNOTATIONS', 'GRADIENTS', 'BACKGROUND-IMAGES', 'CSS-FLOAT', 'CSS-IMAGE-FLOAT', 'CSS-POSITION', 'CSS-PAGE', 'BORDER-RADIUS', 'HYPHENATION', 'ENCRYPTION', 'DIRECTW', 'PROGRESS-BAR', 'IMPORTS');
  4. // *DIRECTW* = Write, WriteText, WriteCell, Text, Shaded_box, AutosizeText
  5. // IMAGES-CORE = [PNG, GIF, and JPG] NB background-images and watermark images
  6. // Text is marked in mpdf_source.php with e.g. :
  7. /*-- TABLES-ADVANCED-BORDERS --*/
  8. /*-- END TABLES-ADVANCED-BORDERS --*/
  9. // *TABLES-ADVANCED-BORDERS*
  10. if (!isset($_POST['generate']) || $_POST['generate']!='generate') {
  11. if (!file_exists('mpdf_source.php')) {
  12. die("ERROR - Could not find mpdf_source.php file in current directory. Please rename mpdf.php as mpdf_source.php");
  13. }
  14. echo '<html>
  15. <head>
  16. <script language=javascript>
  17. checked=false;
  18. function checkedAll (frm1) {
  19. var aa= document.getElementById("frm1");
  20. if (checked == false)
  21. {
  22. checked = true
  23. }
  24. else
  25. {
  26. checked = false
  27. }
  28. for (var i =0; i < aa.elements.length; i++)
  29. {
  30. aa.elements[i].checked = checked;
  31. }
  32. }
  33. </script>
  34. </head>
  35. <body>
  36. <p><span style="color:red; font-weight: bold;">WARNING</span>: This utility will OVERWRITE mpdf.php file in the current directory.</p>
  37. <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>
  38. <div><b>Notes</b>
  39. <ul>
  40. <li>For WMF Images, you must include both IMAGES-CORE and IMAGES-WMF</li>
  41. <li>JPG, PNG and JPG images are supported with IMAGES-CORE</li>
  42. <li>IMAGES-CORE are required for BACKGROUND-IMAGES or WATERMARKS to work</li>
  43. <li>DIRECTW includes the functions to Write directly to the PDF file e.g. Write, WriteText, WriteCell, Text, Shaded_box, AutosizeText</li>
  44. </ul>
  45. </div>
  46. <input type="checkbox" name="checkall" onclick="checkedAll(frm1);"> <i>Select/Unselect All</i><br /><br />
  47. <form id="frm1" action="compress.php" method="POST">
  48. ';
  49. foreach($excl AS $k=>$ex) {
  50. echo '<input type="checkbox" value="1" name="inc['.$ex.']"';
  51. if ($k < 3) {
  52. echo ' checked="checked"';
  53. }
  54. echo ' /> '.$ex.'<br />';
  55. }
  56. echo '<br />
  57. <input type="submit" name="generate" value="generate" />
  58. </form>
  59. </body>
  60. </html>';
  61. exit;
  62. }
  63. $inc = $_POST['inc'];
  64. if (is_array($inc) && count($inc)>0 ) {
  65. foreach($inc AS $i=>$v) {
  66. $key = array_search($i, $excl);
  67. unset($excl[$key]);
  68. }
  69. }
  70. set_magic_quotes_runtime(0);
  71. $l = file('mpdf_source.php');
  72. if (!count($l)) { die("ERROR - Could not find mpdf_source.php file in current directory"); }
  73. $exclflags = array();
  74. $x = '';
  75. foreach($l AS $k=>$ln) {
  76. $exclude = false;
  77. // *XXXXX*
  78. preg_match_all("/\/\/ \*([A-Za-z\-]+)\*/", $ln, $m);
  79. foreach($m[1] AS $mm) {
  80. if (in_array($mm, $excl)) {
  81. $exclude = true;
  82. }
  83. }
  84. /*-- XXXXX --*/
  85. preg_match_all("/\/\*-- ([A-Za-z\-]+) --\*\//", $ln, $m);
  86. foreach($m[1] AS $mm) {
  87. if (in_array($mm, $excl)) {
  88. $exclflags[$mm] = true;
  89. }
  90. $exclude = true;
  91. }
  92. $exclflags = array_unique($exclflags);
  93. /*-- END XXXX --*/
  94. preg_match_all("/\/\*-- END ([A-Za-z\-]+) --\*\//", $ln, $m);
  95. foreach($m[1] AS $mm) {
  96. if (in_array($mm, $excl)) {
  97. unset($exclflags[$mm]);
  98. }
  99. $exclude = true;
  100. }
  101. if (count($exclflags)==0 && !$exclude) {
  102. $x .= $ln;
  103. }
  104. }
  105. $check = file_put_contents('mpdf.php', $x);
  106. if (!$check) { die("ERROR - Could not write to mpdf.php file. Are permissions correctly set?"); }
  107. echo '<p><b>mPDF file generated successfully!</b></p>';
  108. echo '<div>mPDF file size '.number_format((strlen($x)/1024)).' kB</div>';
  109. unset($l);
  110. unset($x);
  111. include('mpdf.php');
  112. $mpdf = new mPDF();
  113. echo '<div>Memory usage on loading mPDF class '.number_format((memory_get_usage(true)/(1024*1024)),2).' MB</div>';
  114. exit;
  115. ?>