compress.php 5.4 KB

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