dompdf_config.inc.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <?php
  2. /**
  3. * DOMPDF - PHP5 HTML to PDF renderer
  4. *
  5. * File: $RCSfile: dompdf_config.inc.php,v $
  6. * Created on: 2004-08-04
  7. *
  8. * Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca>
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this library in the file LICENSE.LGPL; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  23. * 02111-1307 USA
  24. *
  25. * Alternatively, you may distribute this software under the terms of the
  26. * PHP License, version 3.0 or later. A copy of this license should have
  27. * been distributed with this file in the file LICENSE.PHP . If this is not
  28. * the case, you can obtain a copy at http://www.php.net/license/3_0.txt.
  29. *
  30. * The latest version of DOMPDF might be available at:
  31. * http://www.dompdf.com/
  32. *
  33. * @link http://www.dompdf.com/
  34. * @copyright 2004 Benj Carson
  35. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  36. * @contributor Helmut Tischer <htischer@weihenstephan.org>
  37. * @package dompdf
  38. *
  39. * Changes
  40. * @contributor Helmut Tischer <htischer@weihenstephan.org>
  41. * @version 0.5.1.htischer.20090507
  42. * - Allow overriding of configuration settings by calling php script.
  43. * This allows replacing of dompdf by a new version in an application
  44. * without any modification,
  45. * - Optionally separate font cache folder from font folder.
  46. * This allows write protecting the entire installation
  47. * - Add settings to enable/disable additional debug output categories
  48. * - Change some defaults to more practical values
  49. * - Add comments about configuration parameter implications
  50. */
  51. /* $Id: dompdf_config.inc.php 216 2010-03-11 22:49:18Z ryan.masten $ */
  52. error_reporting(E_ERROR);
  53. /**
  54. * The root of your DOMPDF installation
  55. */
  56. define("DOMPDF_DIR", str_replace(DIRECTORY_SEPARATOR, '/', realpath(dirname(__FILE__))));
  57. /**
  58. * The location of the DOMPDF include directory
  59. */
  60. define("DOMPDF_INC_DIR", DOMPDF_DIR . "/include");
  61. /**
  62. * The location of the DOMPDF lib directory
  63. */
  64. define("DOMPDF_LIB_DIR", DOMPDF_DIR . "/lib");
  65. //FIXME: Some function definitions rely on the constants defined by DOMPDF. However, might this location prove problematic?
  66. require_once(DOMPDF_INC_DIR . "/functions.inc.php");
  67. /**
  68. * The location of the DOMPDF font directory
  69. *
  70. * If DOMPDF_FONT_DIR identical to DOMPDF_FONT_CACHE or user executing DOMPDF from the CLI,
  71. * this directory must be writable by the webserver process ().
  72. * *Please note the trailing slash.*
  73. *
  74. * Notes regarding fonts:
  75. * Additional .afm font metrics can be added by executing load_font.php from command line.
  76. * Converting ttf fonts to afm requires the external tool referenced by TTF2AFM
  77. *
  78. * Only the original "Base 14 fonts" are present on all pdf viewers. Additional fonts must
  79. * be embedded in the pdf file or the PDF may not display correctly. This can significantly
  80. * increase file size and could violate copyright provisions of a font. Font embedding is
  81. * not currently supported (? via HT).
  82. *
  83. * Any font specification in the source HTML is translated to the closest font available
  84. * in the font directory.
  85. *
  86. * The pdf standard "Base 14 fonts" are:
  87. * Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique,
  88. * Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique,
  89. * Times-Roman, Times-Bold, Times-BoldItalic, Times-Italic,
  90. * Symbol,
  91. * ZapfDingbats,
  92. *
  93. * *Please note the trailing slash.*
  94. */
  95. define("DOMPDF_FONT_DIR", DOMPDF_DIR . "/lib/fonts/");
  96. /**
  97. * The location of the DOMPDF font cache directory
  98. *
  99. * Note this directory must be writable by the webserver process
  100. * This folder must already exist!
  101. * It contains the .afm files, on demand parsed, converted to php syntax and cached
  102. * This folder can be the same as DOMPDF_FONT_DIR
  103. *
  104. * *Please note the trailing slash.*
  105. */
  106. if (!defined("DOMPDF_FONT_CACHE")) {
  107. define("DOMPDF_FONT_CACHE", DOMPDF_FONT_DIR);
  108. }
  109. /**
  110. * The location of a temporary directory.
  111. *
  112. * The directory specified must be writeable by the webserver process.
  113. * The temporary directory is required to download remote images and when
  114. * using the PFDLib back end.
  115. */
  116. if (!defined('DOMPDF_TEMP_DIR')) {
  117. define("DOMPDF_TEMP_DIR", sys_get_temp_dir());
  118. }
  119. /**
  120. * ==== IMPORTANT ====
  121. *
  122. * dompdf's "chroot": Prevents dompdf from accessing system files or other
  123. * files on the webserver. All local files opened by dompdf must be in a
  124. * subdirectory of this directory. DO NOT set it to '/' since this could
  125. * allow an attacker to use dompdf to read any files on the server. This
  126. * should be an absolute path.
  127. * This is only checked on command line call by dompdf.php, but not by
  128. * direct class use like:
  129. * $dompdf = new DOMPDF(); $dompdf->load_html($htmldata); $dompdf->render(); $pdfdata = $dompdf->output();
  130. */
  131. if (!defined("DOMPDF_CHROOT")) {
  132. define("DOMPDF_CHROOT", realpath(DOMPDF_DIR));
  133. }
  134. /**
  135. * Whether to use Unicode fonts or not.
  136. *
  137. * When set to true the PDF backend must be set to "CPDF" and fonts must be
  138. * loaded via the modified ttf2ufm tool included with dompdf (see below).
  139. * Unicode font metric files (with .ufm extensions) must be created with
  140. * ttf2ufm. load_font.php should do this for you if the TTF2AFM define below
  141. * points to the modified ttf2ufm tool included with dompdf.
  142. *
  143. * When enabled, dompdf can support all Unicode glyphs. Any glyphs used in a
  144. * document must be present in your fonts, however.
  145. *
  146. */
  147. if (!defined("DOMPDF_UNICODE_ENABLED")) {
  148. define("DOMPDF_UNICODE_ENABLED", false);
  149. }
  150. /**
  151. * The path to the tt2pt1 utility (used to convert ttf to afm)
  152. *
  153. * Not strictly necessary, but useful if you would like to install
  154. * additional fonts using the {@link load_font.php} utility.
  155. *
  156. * Windows users should use something like this:
  157. * define("TTF2AFM", "C:\\Program Files\\Ttf2Pt1\\bin\\ttf2pt1.exe");
  158. *
  159. * @link http://ttf2pt1.sourceforge.net/
  160. */
  161. if (!defined("TTF2AFM")) {
  162. define("TTF2AFM", DOMPDF_LIB_DIR ."/ttf2ufm/ttf2ufm-src/ttf2pt1");
  163. //define("TTF2AFM", "/usr/bin/ttf2pt1");
  164. }
  165. /**
  166. * The PDF rendering backend to use
  167. *
  168. * Valid settings are 'PDFLib', 'CPDF' (the bundled R&OS PDF class), 'GD' and
  169. * 'auto'. 'auto' will look for PDFLib and use it if found, or if not it will
  170. * fall back on CPDF. 'GD' renders PDFs to graphic files. {@link
  171. * Canvas_Factory} ultimately determines which rendering class to instantiate
  172. * based on this setting.
  173. *
  174. * Both PDFLib & CPDF rendering backends provide sufficient rendering
  175. * capabilities for dompdf, however additional features (e.g. object,
  176. * image and font support, etc.) differ between backends. Please see
  177. * {@link PDFLib_Adapter} for more information on the PDFLib backend
  178. * and {@link CPDF_Adapter} and lib/class.pdf.php for more information
  179. * on CPDF. Also see the documentation for each backend at the links
  180. * below.
  181. *
  182. * The GD rendering backend is a little different than PDFLib and
  183. * CPDF. Several features of CPDF and PDFLib are not supported or do
  184. * not make any sense when creating image files. For example,
  185. * multiple pages are not supported, nor are PDF 'objects'. Have a
  186. * look at {@link GD_Adapter} for more information. GD support is new
  187. * and experimental, so use it at your own risk.
  188. *
  189. * @link http://www.pdflib.com
  190. * @link http://www.ros.co.nz/pdf
  191. * @link http://www.php.net/image
  192. */
  193. if (!defined("DOMPDF_PDF_BACKEND")) {
  194. define("DOMPDF_PDF_BACKEND", "CPDF");
  195. }
  196. /**
  197. * PDFlib license key
  198. *
  199. * If you are using a licensed, commercial version of PDFlib, specify
  200. * your license key here. If you are using PDFlib-Lite or are evaluating
  201. * the commercial version of PDFlib, comment out this setting.
  202. *
  203. * @link http://www.pdflib.com
  204. *
  205. * If pdflib present in web server and auto or selected explicitely above,
  206. * a real license code must exist!
  207. */
  208. if (!defined("DOMPDF_PDFLIB_LICENSE")) {
  209. #define("DOMPDF_PDFLIB_LICENSE", "your license key here");
  210. }
  211. /**
  212. * html target media view which should be rendered into pdf.
  213. * List of types and parsing rules for future extensions:
  214. * http://www.w3.org/TR/REC-html40/types.html
  215. * screen, tty, tv, projection, handheld, print, braille, aural, all
  216. * Note: aural is deprecated in CSS 2.1 because it is replaced by speech in CSS 3.
  217. * Note, even though the generated pdf file is intended for print output,
  218. * the desired content might be different (e.g. screen or projection view of html file).
  219. * Therefore allow specification of content here.
  220. */
  221. if (!defined("DOMPDF_DEFAULT_MEDIA_TYPE")) {
  222. define("DOMPDF_DEFAULT_MEDIA_TYPE", "screen");
  223. }
  224. /**
  225. * The default paper size.
  226. *
  227. * North America standard is "letter"; other countries generally "a4"
  228. *
  229. * @see CPDF_Adapter::PAPER_SIZES for valid sizes
  230. */
  231. if (!defined("DOMPDF_DEFAULT_PAPER_SIZE")) {
  232. define("DOMPDF_DEFAULT_PAPER_SIZE", "letter");
  233. }
  234. /**
  235. * The default font family
  236. *
  237. * Used if no suitable fonts can be found. This must exist in the font folder.
  238. * @var string
  239. */
  240. if (!defined("DOMPDF_DEFAULT_FONT")) {
  241. define("DOMPDF_DEFAULT_FONT", "serif");
  242. }
  243. /**
  244. * Image DPI setting
  245. *
  246. * This setting determines the default DPI setting for images and fonts. The
  247. * DPI may be overridden for inline images by explictly setting the
  248. * image's width & height style attributes (i.e. if the image's native
  249. * width is 600 pixels and you specify the image's width as 72 points,
  250. * the image will have a DPI of 600 in the rendered PDF. The DPI of
  251. * background images can not be overridden and is controlled entirely
  252. * via this parameter.
  253. *
  254. * For the purposes of DOMPDF, pixels per inch (PPI) = dots per inch (DPI).
  255. * If a size in html is given as px (or without unit as image size),
  256. * this tells the corresponding size in pt.
  257. * This adjusts the relative sizes to be similar to the rendering of the
  258. * html page in a reference browser.
  259. *
  260. * In pdf, always 1 pt = 1/72 inch
  261. *
  262. * Rendering resolution of various browsers in px per inch:
  263. * Windows Firefox and Internet Explorer:
  264. * SystemControl->Display properties->FontResolution: Default:96, largefonts:120, custom:?
  265. * Linux Firefox:
  266. * about:config *resolution: Default:96
  267. * (xorg screen dimension in mm and Desktop font dpi settings are ignored)
  268. *
  269. * Take care about extra font/image zoom factor of browser.
  270. *
  271. * In images, <img> size in pixel attribute, img css style, are overriding
  272. * the real image dimension in px for rendering.
  273. *
  274. * @var int
  275. */
  276. if (!defined("DOMPDF_DPI")) {
  277. define("DOMPDF_DPI", "96");
  278. }
  279. /**
  280. * Enable inline PHP
  281. *
  282. * If this setting is set to true then DOMPDF will automatically evaluate
  283. * inline PHP contained within <script type="text/php"> ... </script> tags.
  284. *
  285. * Enabling this for documents you do not trust (e.g. arbitrary remote html
  286. * pages) is a security risk. Set this option to false if you wish to process
  287. * untrusted documents.
  288. *
  289. * @var bool
  290. */
  291. if (!defined("DOMPDF_ENABLE_PHP")) {
  292. define("DOMPDF_ENABLE_PHP", true);
  293. }
  294. /**
  295. * Enable remote file access
  296. *
  297. * If this setting is set to true, DOMPDF will access remote sites for
  298. * images and CSS files as required.
  299. * This is required for part of test case www/test/image_variants.html through www/examples.php
  300. *
  301. * Attention!
  302. * This can be a security risk, in particular in combination with DOMPDF_ENABLE_PHP and
  303. * allowing remote access to dompdf.php or on allowing remote html code to be passed to
  304. * $dompdf = new DOMPDF(); $dompdf->load_html(...);
  305. * This allows anonymous users to download legally doubtful internet content which on
  306. * tracing back appears to being downloaded by your server, or allows malicious php code
  307. * in remote html pages to be executed by your server with your account privileges.
  308. *
  309. * @var bool
  310. */
  311. if (!defined("DOMPDF_ENABLE_REMOTE")) {
  312. define("DOMPDF_ENABLE_REMOTE", false);
  313. }
  314. /**
  315. * DOMPDF autoload function
  316. *
  317. * If you have an existing autoload function, add a call to this function
  318. * from your existing __autoload() implementation.
  319. *
  320. * TODO: use spl_autoload(), if available
  321. *
  322. * @param string $class
  323. */
  324. function DOMPDF_autoload($class) {
  325. $filename = DOMPDF_INC_DIR . "/" . mb_strtolower($class) . ".cls.php";
  326. if ( is_file($filename) )
  327. require_once($filename);
  328. }
  329. if ( function_exists("spl_autoload_register") ) {
  330. spl_autoload_register("DOMPDF_autoload");
  331. } else if ( !function_exists("__autoload") ) {
  332. /**
  333. * Default __autoload() function
  334. *
  335. * @param string $class
  336. */
  337. function __autoload($class) {
  338. DOMPDF_autoload($class);
  339. }
  340. }
  341. // ### End of user-configurable options ###
  342. /**
  343. * Ensure that PHP is working with text internally using UTF8 character encoding.
  344. */
  345. mb_internal_encoding('UTF-8');
  346. /**
  347. * Global array of warnings generated by DomDocument parser and
  348. * stylesheet class
  349. *
  350. * @var array
  351. */
  352. global $_dompdf_warnings;
  353. $_dompdf_warnings = array();
  354. /**
  355. * If true, $_dompdf_warnings is dumped on script termination when using
  356. * dompdf/dompdf.php or after rendering when using the DOMPDF class.
  357. * When using the class, setting this value to true will prevent you from
  358. * streaming the PDF.
  359. *
  360. * @var bool
  361. */
  362. global $_dompdf_show_warnings;
  363. $_dompdf_show_warnings = false;
  364. /**
  365. * If true, the entire tree is dumped to stdout in dompdf.cls.php.
  366. * Setting this value to true will prevent you from streaming the PDF.
  367. *
  368. * @var bool
  369. */
  370. global $_dompdf_debug;
  371. $_dompdf_debug = false;
  372. /**
  373. * Array of enabled debug message types
  374. *
  375. * @var array
  376. */
  377. global $_DOMPDF_DEBUG_TYPES;
  378. $_DOMPDF_DEBUG_TYPES = array(); //array("page-break" => 1);
  379. /* Optionally enable different classes of debug output before the pdf content.
  380. * Visible if displaying pdf as text,
  381. * E.g. on repeated display of same pdf in browser when pdf is not taken out of
  382. * the browser cache and the premature output prevents setting of the mime type.
  383. */
  384. if (!defined('DEBUGPNG')) {
  385. define('DEBUGPNG',0);
  386. }
  387. if (!defined('DEBUGKEEPTEMP')) {
  388. define('DEBUGKEEPTEMP',0);
  389. }
  390. if (!defined('DEBUGCSS')) {
  391. define('DEBUGCSS',0);
  392. }