dompdf_config.inc.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <?php
  2. /**
  3. * @package dompdf
  4. * @link http://dompdf.github.com/
  5. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  6. * @author Helmut Tischer <htischer@weihenstephan.org>
  7. * @author Fabien Ménager <fabien.menager@gmail.com>
  8. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  9. */
  10. //error_reporting(E_STRICT | E_ALL | E_DEPRECATED);
  11. //ini_set("display_errors", 1);
  12. PHP_VERSION >= 5.0 or die("DOMPDF requires PHP 5.0+");
  13. /**
  14. * The root of your DOMPDF installation
  15. */
  16. define("DOMPDF_DIR", str_replace(DIRECTORY_SEPARATOR, '/', realpath(dirname(__FILE__))));
  17. /**
  18. * The location of the DOMPDF include directory
  19. */
  20. define("DOMPDF_INC_DIR", DOMPDF_DIR . "/include");
  21. /**
  22. * The location of the DOMPDF lib directory
  23. */
  24. define("DOMPDF_LIB_DIR", DOMPDF_DIR . "/lib");
  25. /**
  26. * Some installations don't have $_SERVER['DOCUMENT_ROOT']
  27. * http://fyneworks.blogspot.com/2007/08/php-documentroot-in-iis-windows-servers.html
  28. */
  29. if( !isset($_SERVER['DOCUMENT_ROOT']) ) {
  30. $path = "";
  31. if ( isset($_SERVER['SCRIPT_FILENAME']) )
  32. $path = $_SERVER['SCRIPT_FILENAME'];
  33. elseif ( isset($_SERVER['PATH_TRANSLATED']) )
  34. $path = str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']);
  35. $_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr($path, 0, 0-strlen($_SERVER['PHP_SELF'])));
  36. }
  37. /** Include the custom config file if it exists */
  38. if ( file_exists(DOMPDF_DIR . "/dompdf_config.custom.inc.php") ){
  39. require_once(DOMPDF_DIR . "/dompdf_config.custom.inc.php");
  40. }
  41. //FIXME: Some function definitions rely on the constants defined by DOMPDF. However, might this location prove problematic?
  42. require_once(DOMPDF_INC_DIR . "/functions.inc.php");
  43. /**
  44. * Username and password used by the configuration utility in www/
  45. */
  46. def("DOMPDF_ADMIN_USERNAME", "user");
  47. def("DOMPDF_ADMIN_PASSWORD", "password");
  48. /**
  49. * The location of the DOMPDF font directory
  50. *
  51. * If DOMPDF_FONT_DIR identical to DOMPDF_FONT_CACHE or user executing DOMPDF from the CLI,
  52. * this directory must be writable by the webserver process ().
  53. * *Please note the trailing slash.*
  54. *
  55. * Notes regarding fonts:
  56. * Additional .afm font metrics can be added by executing load_font.php from command line.
  57. *
  58. * Only the original "Base 14 fonts" are present on all pdf viewers. Additional fonts must
  59. * be embedded in the pdf file or the PDF may not display correctly. This can significantly
  60. * increase file size and could violate copyright provisions of a font. Font subsetting is
  61. * not currently supported.
  62. *
  63. * Any font specification in the source HTML is translated to the closest font available
  64. * in the font directory.
  65. *
  66. * The pdf standard "Base 14 fonts" are:
  67. * Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique,
  68. * Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique,
  69. * Times-Roman, Times-Bold, Times-BoldItalic, Times-Italic,
  70. * Symbol,
  71. * ZapfDingbats,
  72. *
  73. * *Please note the trailing slash.*
  74. */
  75. def("DOMPDF_FONT_DIR", DOMPDF_DIR . "/lib/fonts/");
  76. /**
  77. * The location of the DOMPDF font cache directory
  78. *
  79. * Note this directory must be writable by the webserver process
  80. * This folder must already exist!
  81. * It contains the .afm files, on demand parsed, converted to php syntax and cached
  82. * This folder can be the same as DOMPDF_FONT_DIR
  83. */
  84. def("DOMPDF_FONT_CACHE", DOMPDF_FONT_DIR);
  85. /**
  86. * The location of a temporary directory.
  87. *
  88. * The directory specified must be writeable by the webserver process.
  89. * The temporary directory is required to download remote images and when
  90. * using the PFDLib back end.
  91. */
  92. def("DOMPDF_TEMP_DIR", sys_get_temp_dir());
  93. /**
  94. * ==== IMPORTANT ====
  95. *
  96. * dompdf's "chroot": Prevents dompdf from accessing system files or other
  97. * files on the webserver. All local files opened by dompdf must be in a
  98. * subdirectory of this directory. DO NOT set it to '/' since this could
  99. * allow an attacker to use dompdf to read any files on the server. This
  100. * should be an absolute path.
  101. * This is only checked on command line call by dompdf.php, but not by
  102. * direct class use like:
  103. * $dompdf = new DOMPDF(); $dompdf->load_html($htmldata); $dompdf->render(); $pdfdata = $dompdf->output();
  104. */
  105. def("DOMPDF_CHROOT", realpath(DOMPDF_DIR));
  106. /**
  107. * Whether to use Unicode fonts or not.
  108. *
  109. * When set to true the PDF backend must be set to "CPDF" and fonts must be
  110. * loaded via load_font.php.
  111. *
  112. * When enabled, dompdf can support all Unicode glyphs. Any glyphs used in a
  113. * document must be present in your fonts, however.
  114. */
  115. def("DOMPDF_UNICODE_ENABLED", true);
  116. /**
  117. * Whether to make font subsetting or not.
  118. */
  119. def("DOMPDF_ENABLE_FONTSUBSETTING", false);
  120. /**
  121. * The PDF rendering backend to use
  122. *
  123. * Valid settings are 'PDFLib', 'CPDF' (the bundled R&OS PDF class), 'GD' and
  124. * 'auto'. 'auto' will look for PDFLib and use it if found, or if not it will
  125. * fall back on CPDF. 'GD' renders PDFs to graphic files. {@link
  126. * Canvas_Factory} ultimately determines which rendering class to instantiate
  127. * based on this setting.
  128. *
  129. * Both PDFLib & CPDF rendering backends provide sufficient rendering
  130. * capabilities for dompdf, however additional features (e.g. object,
  131. * image and font support, etc.) differ between backends. Please see
  132. * {@link PDFLib_Adapter} for more information on the PDFLib backend
  133. * and {@link CPDF_Adapter} and lib/class.pdf.php for more information
  134. * on CPDF. Also see the documentation for each backend at the links
  135. * below.
  136. *
  137. * The GD rendering backend is a little different than PDFLib and
  138. * CPDF. Several features of CPDF and PDFLib are not supported or do
  139. * not make any sense when creating image files. For example,
  140. * multiple pages are not supported, nor are PDF 'objects'. Have a
  141. * look at {@link GD_Adapter} for more information. GD support is new
  142. * and experimental, so use it at your own risk.
  143. *
  144. * @link http://www.pdflib.com
  145. * @link http://www.ros.co.nz/pdf
  146. * @link http://www.php.net/image
  147. */
  148. def("DOMPDF_PDF_BACKEND", "CPDF");
  149. /**
  150. * PDFlib license key
  151. *
  152. * If you are using a licensed, commercial version of PDFlib, specify
  153. * your license key here. If you are using PDFlib-Lite or are evaluating
  154. * the commercial version of PDFlib, comment out this setting.
  155. *
  156. * @link http://www.pdflib.com
  157. *
  158. * If pdflib present in web server and auto or selected explicitely above,
  159. * a real license code must exist!
  160. */
  161. //def("DOMPDF_PDFLIB_LICENSE", "your license key here");
  162. /**
  163. * html target media view which should be rendered into pdf.
  164. * List of types and parsing rules for future extensions:
  165. * http://www.w3.org/TR/REC-html40/types.html
  166. * screen, tty, tv, projection, handheld, print, braille, aural, all
  167. * Note: aural is deprecated in CSS 2.1 because it is replaced by speech in CSS 3.
  168. * Note, even though the generated pdf file is intended for print output,
  169. * the desired content might be different (e.g. screen or projection view of html file).
  170. * Therefore allow specification of content here.
  171. */
  172. def("DOMPDF_DEFAULT_MEDIA_TYPE", "screen");
  173. /**
  174. * The default paper size.
  175. *
  176. * North America standard is "letter"; other countries generally "a4"
  177. *
  178. * @see CPDF_Adapter::PAPER_SIZES for valid sizes
  179. */
  180. def("DOMPDF_DEFAULT_PAPER_SIZE", "letter");
  181. /**
  182. * The default font family
  183. *
  184. * Used if no suitable fonts can be found. This must exist in the font folder.
  185. * @var string
  186. */
  187. def("DOMPDF_DEFAULT_FONT", "serif");
  188. /**
  189. * Image DPI setting
  190. *
  191. * This setting determines the default DPI setting for images and fonts. The
  192. * DPI may be overridden for inline images by explictly setting the
  193. * image's width & height style attributes (i.e. if the image's native
  194. * width is 600 pixels and you specify the image's width as 72 points,
  195. * the image will have a DPI of 600 in the rendered PDF. The DPI of
  196. * background images can not be overridden and is controlled entirely
  197. * via this parameter.
  198. *
  199. * For the purposes of DOMPDF, pixels per inch (PPI) = dots per inch (DPI).
  200. * If a size in html is given as px (or without unit as image size),
  201. * this tells the corresponding size in pt.
  202. * This adjusts the relative sizes to be similar to the rendering of the
  203. * html page in a reference browser.
  204. *
  205. * In pdf, always 1 pt = 1/72 inch
  206. *
  207. * Rendering resolution of various browsers in px per inch:
  208. * Windows Firefox and Internet Explorer:
  209. * SystemControl->Display properties->FontResolution: Default:96, largefonts:120, custom:?
  210. * Linux Firefox:
  211. * about:config *resolution: Default:96
  212. * (xorg screen dimension in mm and Desktop font dpi settings are ignored)
  213. *
  214. * Take care about extra font/image zoom factor of browser.
  215. *
  216. * In images, <img> size in pixel attribute, img css style, are overriding
  217. * the real image dimension in px for rendering.
  218. *
  219. * @var int
  220. */
  221. def("DOMPDF_DPI", 96);
  222. /**
  223. * Enable inline PHP
  224. *
  225. * If this setting is set to true then DOMPDF will automatically evaluate
  226. * inline PHP contained within <script type="text/php"> ... </script> tags.
  227. *
  228. * Enabling this for documents you do not trust (e.g. arbitrary remote html
  229. * pages) is a security risk. Set this option to false if you wish to process
  230. * untrusted documents.
  231. *
  232. * @var bool
  233. */
  234. def("DOMPDF_ENABLE_PHP", false);
  235. /**
  236. * Enable inline Javascript
  237. *
  238. * If this setting is set to true then DOMPDF will automatically insert
  239. * JavaScript code contained within <script type="text/javascript"> ... </script> tags.
  240. *
  241. * @var bool
  242. */
  243. def("DOMPDF_ENABLE_JAVASCRIPT", true);
  244. /**
  245. * Enable remote file access
  246. *
  247. * If this setting is set to true, DOMPDF will access remote sites for
  248. * images and CSS files as required.
  249. * This is required for part of test case www/test/image_variants.html through www/examples.php
  250. *
  251. * Attention!
  252. * This can be a security risk, in particular in combination with DOMPDF_ENABLE_PHP and
  253. * allowing remote access to dompdf.php or on allowing remote html code to be passed to
  254. * $dompdf = new DOMPDF(); $dompdf->load_html(...);
  255. * This allows anonymous users to download legally doubtful internet content which on
  256. * tracing back appears to being downloaded by your server, or allows malicious php code
  257. * in remote html pages to be executed by your server with your account privileges.
  258. *
  259. * @var bool
  260. */
  261. def("DOMPDF_ENABLE_REMOTE", false);
  262. /**
  263. * The debug output log
  264. * @var string
  265. */
  266. def("DOMPDF_LOG_OUTPUT_FILE", DOMPDF_FONT_DIR."log.htm");
  267. /**
  268. * A ratio applied to the fonts height to be more like browsers' line height
  269. */
  270. def("DOMPDF_FONT_HEIGHT_RATIO", 1.1);
  271. /**
  272. * Enable CSS float
  273. *
  274. * Allows people to disabled CSS float support
  275. * @var bool
  276. */
  277. def("DOMPDF_ENABLE_CSS_FLOAT", false);
  278. /**
  279. * Prepend the DOMPDF autoload function the spl_autoload stack
  280. *
  281. * @var bool
  282. */
  283. def("DOMPDF_AUTOLOAD_PREPEND", false);
  284. /**
  285. * Use the more-than-experimental HTML5 Lib parser
  286. */
  287. def("DOMPDF_ENABLE_HTML5PARSER", false);
  288. require_once(DOMPDF_LIB_DIR . "/html5lib/Parser.php");
  289. // ### End of user-configurable options ###
  290. // is composer running?
  291. if (!class_exists("ComposerAutoloaderInit")) {
  292. if (file_exists(DOMPDF_DIR . "/vendor/autoload.php")) {
  293. // development mode - composer is installed locally
  294. require_once(DOMPDF_DIR . "/vendor/autoload.php");
  295. } else {
  296. // composer is not installed - use our custom autoloader
  297. require_once(DOMPDF_INC_DIR . "/autoload.inc.php");
  298. }
  299. }
  300. // check for php-font-lib
  301. if (!class_exists('Font')) {
  302. if (file_exists(DOMPDF_LIB_DIR . "/php-font-lib/classes/font.cls.php")) {
  303. require_once(DOMPDF_LIB_DIR . "/php-font-lib/classes/font.cls.php");
  304. } else {
  305. exit("PHP-font-lib must either be installed via composer or copied to lib/php-font-lib\n");
  306. }
  307. }
  308. /**
  309. * Ensure that PHP is working with text internally using UTF8 character encoding.
  310. */
  311. mb_internal_encoding('UTF-8');
  312. /**
  313. * Global array of warnings generated by DomDocument parser and
  314. * stylesheet class
  315. *
  316. * @var array
  317. */
  318. global $_dompdf_warnings;
  319. $_dompdf_warnings = array();
  320. /**
  321. * If true, $_dompdf_warnings is dumped on script termination when using
  322. * dompdf/dompdf.php or after rendering when using the DOMPDF class.
  323. * When using the class, setting this value to true will prevent you from
  324. * streaming the PDF.
  325. *
  326. * @var bool
  327. */
  328. global $_dompdf_show_warnings;
  329. $_dompdf_show_warnings = false;
  330. /**
  331. * If true, the entire tree is dumped to stdout in dompdf.cls.php.
  332. * Setting this value to true will prevent you from streaming the PDF.
  333. *
  334. * @var bool
  335. */
  336. global $_dompdf_debug;
  337. $_dompdf_debug = false;
  338. /**
  339. * Array of enabled debug message types
  340. *
  341. * @var array
  342. */
  343. global $_DOMPDF_DEBUG_TYPES;
  344. $_DOMPDF_DEBUG_TYPES = array(); //array("page-break" => 1);
  345. /* Optionally enable different classes of debug output before the pdf content.
  346. * Visible if displaying pdf as text,
  347. * E.g. on repeated display of same pdf in browser when pdf is not taken out of
  348. * the browser cache and the premature output prevents setting of the mime type.
  349. */
  350. def('DEBUGPNG', false);
  351. def('DEBUGKEEPTEMP', false);
  352. def('DEBUGCSS', false);
  353. /* Layout debugging. Will display rectangles around different block levels.
  354. * Visible in the PDF itself.
  355. */
  356. def('DEBUG_LAYOUT', false);
  357. def('DEBUG_LAYOUT_LINES', true);
  358. def('DEBUG_LAYOUT_BLOCKS', true);
  359. def('DEBUG_LAYOUT_INLINE', true);
  360. def('DEBUG_LAYOUT_PADDINGBOX', true);