No Description

dompdf_config.inc.php 13KB

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