]> BookStack Code Mirror - bookstack/blob - app/Config/dompdf.php
Applied styleci changes, updated dev version & readme roadmap
[bookstack] / app / Config / dompdf.php
1 <?php
2
3 /**
4  * DOMPDF configuration options.
5  *
6  * Changes to these config files are not supported by BookStack and may break upon updates.
7  * Configuration should be altered via the `.env` file or environment variables.
8  * Do not edit this file unless you're happy to maintain any changes yourself.
9  */
10 $dompdfPaperSizeMap = [
11     'a4'     => 'a4',
12     'letter' => 'letter',
13 ];
14
15 return [
16
17     'show_warnings' => false,   // Throw an Exception on warnings from dompdf
18
19     'options'       => [
20         /**
21          * The location of the DOMPDF font directory.
22          *
23          * The location of the directory where DOMPDF will store fonts and font metrics
24          * Note: This directory must exist and be writable by the webserver process.
25          * *Please note the trailing slash.*
26          *
27          * Notes regarding fonts:
28          * Additional .afm font metrics can be added by executing load_font.php from command line.
29          *
30          * Only the original "Base 14 fonts" are present on all pdf viewers. Additional fonts must
31          * be embedded in the pdf file or the PDF may not display correctly. This can significantly
32          * increase file size unless font subsetting is enabled. Before embedding a font please
33          * review your rights under the font license.
34          *
35          * Any font specification in the source HTML is translated to the closest font available
36          * in the font directory.
37          *
38          * The pdf standard "Base 14 fonts" are:
39          * Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique,
40          * Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique,
41          * Times-Roman, Times-Bold, Times-BoldItalic, Times-Italic,
42          * Symbol, ZapfDingbats.
43          */
44         'font_dir' => storage_path('fonts/'),  // advised by dompdf (https://github.com/dompdf/dompdf/pull/782)
45
46         /**
47          * The location of the DOMPDF font cache directory.
48          *
49          * This directory contains the cached font metrics for the fonts used by DOMPDF.
50          * This directory can be the same as DOMPDF_FONT_DIR
51          *
52          * Note: This directory must exist and be writable by the webserver process.
53          */
54         'font_cache' => storage_path('fonts/'),
55
56         /**
57          * The location of a temporary directory.
58          *
59          * The directory specified must be writeable by the webserver process.
60          * The temporary directory is required to download remote images and when
61          * using the PFDLib back end.
62          */
63         'temp_dir' => sys_get_temp_dir(),
64
65         /**
66          * ==== IMPORTANT ====.
67          *
68          * dompdf's "chroot": Prevents dompdf from accessing system files or other
69          * files on the webserver.  All local files opened by dompdf must be in a
70          * subdirectory of this directory.  DO NOT set it to '/' since this could
71          * allow an attacker to use dompdf to read any files on the server.  This
72          * should be an absolute path.
73          * This is only checked on command line call by dompdf.php, but not by
74          * direct class use like:
75          * $dompdf = new DOMPDF();  $dompdf->load_html($htmldata); $dompdf->render(); $pdfdata = $dompdf->output();
76          */
77         'chroot' => realpath(public_path()),
78
79         /**
80          * Protocol whitelist.
81          *
82          * Protocols and PHP wrappers allowed in URIs, and the validation rules
83          * that determine if a resouce may be loaded. Full support is not guaranteed
84          * for the protocols/wrappers specified
85          * by this array.
86          *
87          * @var array
88          */
89         'allowed_protocols' => [
90             'file://'  => ['rules' => []],
91             'http://'  => ['rules' => []],
92             'https://' => ['rules' => []],
93         ],
94
95         /**
96          * @var string
97          */
98         'log_output_file' => null,
99
100         /**
101          * Whether to enable font subsetting or not.
102          */
103         'enable_fontsubsetting' => false,
104
105         /**
106          * The PDF rendering backend to use.
107          *
108          * Valid settings are 'PDFLib', 'CPDF' (the bundled R&OS PDF class), 'GD' and
109          * 'auto'. 'auto' will look for PDFLib and use it if found, or if not it will
110          * fall back on CPDF. 'GD' renders PDFs to graphic files. {@link * Canvas_Factory} ultimately determines which rendering class to instantiate
111          * based on this setting.
112          *
113          * Both PDFLib & CPDF rendering backends provide sufficient rendering
114          * capabilities for dompdf, however additional features (e.g. object,
115          * image and font support, etc.) differ between backends.  Please see
116          * {@link PDFLib_Adapter} for more information on the PDFLib backend
117          * and {@link CPDF_Adapter} and lib/class.pdf.php for more information
118          * on CPDF. Also see the documentation for each backend at the links
119          * below.
120          *
121          * The GD rendering backend is a little different than PDFLib and
122          * CPDF. Several features of CPDF and PDFLib are not supported or do
123          * not make any sense when creating image files.  For example,
124          * multiple pages are not supported, nor are PDF 'objects'.  Have a
125          * look at {@link GD_Adapter} for more information.  GD support is
126          * experimental, so use it at your own risk.
127          *
128          * @link http://www.pdflib.com
129          * @link http://www.ros.co.nz/pdf
130          * @link http://www.php.net/image
131          */
132         'pdf_backend' => 'CPDF',
133
134         /**
135          * PDFlib license key.
136          *
137          * If you are using a licensed, commercial version of PDFlib, specify
138          * your license key here.  If you are using PDFlib-Lite or are evaluating
139          * the commercial version of PDFlib, comment out this setting.
140          *
141          * @link http://www.pdflib.com
142          *
143          * If pdflib present in web server and auto or selected explicitely above,
144          * a real license code must exist!
145          */
146         //"DOMPDF_PDFLIB_LICENSE" => "your license key here",
147
148         /**
149          * html target media view which should be rendered into pdf.
150          * List of types and parsing rules for future extensions:
151          * http://www.w3.org/TR/REC-html40/types.html
152          *   screen, tty, tv, projection, handheld, print, braille, aural, all
153          * Note: aural is deprecated in CSS 2.1 because it is replaced by speech in CSS 3.
154          * Note, even though the generated pdf file is intended for print output,
155          * the desired content might be different (e.g. screen or projection view of html file).
156          * Therefore allow specification of content here.
157          */
158         'default_media_type' => 'print',
159
160         /**
161          * The default paper size.
162          *
163          * North America standard is "letter"; other countries generally "a4"
164          *
165          * @see CPDF_Adapter::PAPER_SIZES for valid sizes ('letter', 'legal', 'A4', etc.)
166          */
167         'default_paper_size' => $dompdfPaperSizeMap[env('EXPORT_PAGE_SIZE', 'a4')] ?? 'a4',
168
169         /**
170          * The default paper orientation.
171          *
172          * The orientation of the page (portrait or landscape).
173          *
174          * @var string
175          */
176         'default_paper_orientation' => 'portrait',
177
178         /**
179          * The default font family.
180          *
181          * Used if no suitable fonts can be found. This must exist in the font folder.
182          *
183          * @var string
184          */
185         'default_font' => 'dejavu sans',
186
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.
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         'dpi' => 96,
221
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         'enable_php' => false,
235
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         'enable_javascript' => false,
245
246         /**
247          * Enable remote file access.
248          *
249          * If this setting is set to true, DOMPDF will access remote sites for
250          * images and CSS files as required.
251          * This is required for part of test case www/test/image_variants.html through www/examples.php
252          *
253          * Attention!
254          * This can be a security risk, in particular in combination with DOMPDF_ENABLE_PHP and
255          * allowing remote access to dompdf.php or on allowing remote html code to be passed to
256          * $dompdf = new DOMPDF(, $dompdf->load_html(...,
257          * This allows anonymous users to download legally doubtful internet content which on
258          * tracing back appears to being downloaded by your server, or allows malicious php code
259          * in remote html pages to be executed by your server with your account privileges.
260          *
261          * @var bool
262          */
263         'enable_remote' => env('ALLOW_UNTRUSTED_SERVER_FETCHING', false),
264
265         /**
266          * A ratio applied to the fonts height to be more like browsers' line height.
267          */
268         'font_height_ratio' => 1.1,
269
270         /**
271          * Enable CSS float.
272          *
273          * Allows people to disabled CSS float support
274          *
275          * @var bool
276          */
277         'enable_css_float' => true,
278
279         /**
280          * Use the HTML5 Lib parser.
281          *
282          * @deprecated This feature is now always on in dompdf 2.x
283          *
284          * @var bool
285          */
286         'enable_html5_parser' => true,
287     ],
288
289 ];