]> BookStack Code Mirror - bookstack/blob - app/Config/exports.php
PDF: Started new command option, merged options, simplified dompdf
[bookstack] / app / Config / exports.php
1 <?php
2
3 /**
4  * Export 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
11 $snappyPaperSizeMap = [
12     'a4'     => 'A4',
13     'letter' => 'Letter',
14 ];
15
16 $dompdfPaperSizeMap = [
17     'a4'     => 'a4',
18     'letter' => 'letter',
19 ];
20
21 $exportPageSize = env('EXPORT_PAGE_SIZE', 'a4');
22
23 return [
24
25     // Set a command which can be used to convert a HTML file into a PDF file.
26     // When false this will not be used.
27     // String values represent the command to be called for conversion.
28     // Supports '{input_html_path}' and '{output_pdf_path}' placeholder values.
29     // Example: EXPORT_PDF_COMMAND="/scripts/convert.sh {input_html_path} {output_pdf_path}"
30     'pdf_command' => env('EXPORT_PDF_COMMAND', false),
31
32     // 2024-04: Snappy/WKHTMLtoPDF now considered deprecated in regard to BookStack support.
33     'snappy' => [
34         'pdf' => [
35             'enabled' => true,
36             'binary'  => file_exists(base_path('wkhtmltopdf')) ? base_path('wkhtmltopdf') : env('WKHTMLTOPDF', false),
37             'timeout' => false,
38             'options' => [
39                 'outline'   => true,
40                 'page-size' => $snappyPaperSizeMap[$exportPageSize] ?? 'A4',
41             ],
42             'env'     => [],
43         ],
44         'image' => [
45             'enabled' => false,
46             'binary'  => '/usr/local/bin/wkhtmltoimage',
47             'timeout' => false,
48             'options' => [],
49             'env'     => [],
50         ],
51     ],
52
53     'dompdf' => [
54         /**
55          * The location of the DOMPDF font directory.
56          *
57          * The location of the directory where DOMPDF will store fonts and font metrics
58          * Note: This directory must exist and be writable by the webserver process.
59          * *Please note the trailing slash.*
60          *
61          * Notes regarding fonts:
62          * Additional .afm font metrics can be added by executing load_font.php from command line.
63          *
64          * Only the original "Base 14 fonts" are present on all pdf viewers. Additional fonts must
65          * be embedded in the pdf file or the PDF may not display correctly. This can significantly
66          * increase file size unless font subsetting is enabled. Before embedding a font please
67          * review your rights under the font license.
68          *
69          * Any font specification in the source HTML is translated to the closest font available
70          * in the font directory.
71          *
72          * The pdf standard "Base 14 fonts" are:
73          * Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique,
74          * Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique,
75          * Times-Roman, Times-Bold, Times-BoldItalic, Times-Italic,
76          * Symbol, ZapfDingbats.
77          */
78         'font_dir' => storage_path('fonts/'),  // advised by dompdf (https://github.com/dompdf/dompdf/pull/782)
79
80         /**
81          * The location of the DOMPDF font cache directory.
82          *
83          * This directory contains the cached font metrics for the fonts used by DOMPDF.
84          * This directory can be the same as DOMPDF_FONT_DIR
85          *
86          * Note: This directory must exist and be writable by the webserver process.
87          */
88         'font_cache' => storage_path('fonts/'),
89
90         /**
91          * The location of a temporary directory.
92          *
93          * The directory specified must be writeable by the webserver process.
94          * The temporary directory is required to download remote images and when
95          * using the PFDLib back end.
96          */
97         'temp_dir' => sys_get_temp_dir(),
98
99         /**
100          * ==== IMPORTANT ====.
101          *
102          * dompdf's "chroot": Prevents dompdf from accessing system files or other
103          * files on the webserver.  All local files opened by dompdf must be in a
104          * subdirectory of this directory.  DO NOT set it to '/' since this could
105          * allow an attacker to use dompdf to read any files on the server.  This
106          * should be an absolute path.
107          * This is only checked on command line call by dompdf.php, but not by
108          * direct class use like:
109          * $dompdf = new DOMPDF();  $dompdf->load_html($htmldata); $dompdf->render(); $pdfdata = $dompdf->output();
110          */
111         'chroot' => realpath(public_path()),
112
113         /**
114          * Protocol whitelist.
115          *
116          * Protocols and PHP wrappers allowed in URIs, and the validation rules
117          * that determine if a resouce may be loaded. Full support is not guaranteed
118          * for the protocols/wrappers specified
119          * by this array.
120          *
121          * @var array
122          */
123         'allowed_protocols' => [
124             'file://'  => ['rules' => []],
125             'http://'  => ['rules' => []],
126             'https://' => ['rules' => []],
127         ],
128
129         /**
130          * @var string
131          */
132         'log_output_file' => null,
133
134         /**
135          * Whether to enable font subsetting or not.
136          */
137         'enable_font_subsetting' => false,
138
139         /**
140          * The PDF rendering backend to use.
141          *
142          * Valid settings are 'PDFLib', 'CPDF' (the bundled R&OS PDF class), 'GD' and
143          * 'auto'. 'auto' will look for PDFLib and use it if found, or if not it will
144          * fall back on CPDF. 'GD' renders PDFs to graphic files. {@link * Canvas_Factory} ultimately determines which rendering class to instantiate
145          * based on this setting.
146          *
147          * Both PDFLib & CPDF rendering backends provide sufficient rendering
148          * capabilities for dompdf, however additional features (e.g. object,
149          * image and font support, etc.) differ between backends.  Please see
150          * {@link PDFLib_Adapter} for more information on the PDFLib backend
151          * and {@link CPDF_Adapter} and lib/class.pdf.php for more information
152          * on CPDF. Also see the documentation for each backend at the links
153          * below.
154          *
155          * The GD rendering backend is a little different than PDFLib and
156          * CPDF. Several features of CPDF and PDFLib are not supported or do
157          * not make any sense when creating image files.  For example,
158          * multiple pages are not supported, nor are PDF 'objects'.  Have a
159          * look at {@link GD_Adapter} for more information.  GD support is
160          * experimental, so use it at your own risk.
161          *
162          * @link http://www.pdflib.com
163          * @link http://www.ros.co.nz/pdf
164          * @link http://www.php.net/image
165          */
166         'pdf_backend' => 'CPDF',
167
168         /**
169          * PDFlib license key.
170          *
171          * If you are using a licensed, commercial version of PDFlib, specify
172          * your license key here.  If you are using PDFlib-Lite or are evaluating
173          * the commercial version of PDFlib, comment out this setting.
174          *
175          * @link http://www.pdflib.com
176          *
177          * If pdflib present in web server and auto or selected explicitely above,
178          * a real license code must exist!
179          */
180         //"DOMPDF_PDFLIB_LICENSE" => "your license key here",
181
182         /**
183          * html target media view which should be rendered into pdf.
184          * List of types and parsing rules for future extensions:
185          * http://www.w3.org/TR/REC-html40/types.html
186          *   screen, tty, tv, projection, handheld, print, braille, aural, all
187          * Note: aural is deprecated in CSS 2.1 because it is replaced by speech in CSS 3.
188          * Note, even though the generated pdf file is intended for print output,
189          * the desired content might be different (e.g. screen or projection view of html file).
190          * Therefore allow specification of content here.
191          */
192         'default_media_type' => 'print',
193
194         /**
195          * The default paper size.
196          *
197          * North America standard is "letter"; other countries generally "a4"
198          *
199          * @see CPDF_Adapter::PAPER_SIZES for valid sizes ('letter', 'legal', 'A4', etc.)
200          */
201         'default_paper_size' => $dompdfPaperSizeMap[$exportPageSize] ?? 'a4',
202
203         /**
204          * The default paper orientation.
205          *
206          * The orientation of the page (portrait or landscape).
207          *
208          * @var string
209          */
210         'default_paper_orientation' => 'portrait',
211
212         /**
213          * The default font family.
214          *
215          * Used if no suitable fonts can be found. This must exist in the font folder.
216          *
217          * @var string
218          */
219         'default_font' => 'dejavu sans',
220
221         /**
222          * Image DPI setting.
223          *
224          * This setting determines the default DPI setting for images and fonts.  The
225          * DPI may be overridden for inline images by explictly setting the
226          * image's width & height style attributes (i.e. if the image's native
227          * width is 600 pixels and you specify the image's width as 72 points,
228          * the image will have a DPI of 600 in the rendered PDF.  The DPI of
229          * background images can not be overridden and is controlled entirely
230          * via this parameter.
231          *
232          * For the purposes of DOMPDF, pixels per inch (PPI) = dots per inch (DPI).
233          * If a size in html is given as px (or without unit as image size),
234          * this tells the corresponding size in pt.
235          * This adjusts the relative sizes to be similar to the rendering of the
236          * html page in a reference browser.
237          *
238          * In pdf, always 1 pt = 1/72 inch
239          *
240          * Rendering resolution of various browsers in px per inch:
241          * Windows Firefox and Internet Explorer:
242          *   SystemControl->Display properties->FontResolution: Default:96, largefonts:120, custom:?
243          * Linux Firefox:
244          *   about:config *resolution: Default:96
245          *   (xorg screen dimension in mm and Desktop font dpi settings are ignored)
246          *
247          * Take care about extra font/image zoom factor of browser.
248          *
249          * In images, <img> size in pixel attribute, img css style, are overriding
250          * the real image dimension in px for rendering.
251          *
252          * @var int
253          */
254         'dpi' => 96,
255
256         /**
257          * Enable inline PHP.
258          *
259          * If this setting is set to true then DOMPDF will automatically evaluate
260          * inline PHP contained within <script type="text/php"> ... </script> tags.
261          *
262          * Enabling this for documents you do not trust (e.g. arbitrary remote html
263          * pages) is a security risk.  Set this option to false if you wish to process
264          * untrusted documents.
265          *
266          * @var bool
267          */
268         'enable_php' => false,
269
270         /**
271          * Enable inline Javascript.
272          *
273          * If this setting is set to true then DOMPDF will automatically insert
274          * JavaScript code contained within <script type="text/javascript"> ... </script> tags.
275          *
276          * @var bool
277          */
278         'enable_javascript' => false,
279
280         /**
281          * Enable remote file access.
282          *
283          * If this setting is set to true, DOMPDF will access remote sites for
284          * images and CSS files as required.
285          * This is required for part of test case www/test/image_variants.html through www/examples.php
286          *
287          * Attention!
288          * This can be a security risk, in particular in combination with DOMPDF_ENABLE_PHP and
289          * allowing remote access to dompdf.php or on allowing remote html code to be passed to
290          * $dompdf = new DOMPDF(, $dompdf->load_html(...,
291          * This allows anonymous users to download legally doubtful internet content which on
292          * tracing back appears to being downloaded by your server, or allows malicious php code
293          * in remote html pages to be executed by your server with your account privileges.
294          *
295          * @var bool
296          */
297         'enable_remote' => env('ALLOW_UNTRUSTED_SERVER_FETCHING', false),
298
299         /**
300          * A ratio applied to the fonts height to be more like browsers' line height.
301          */
302         'font_height_ratio' => 1.1,
303
304         /**
305          * Use the HTML5 Lib parser.
306          *
307          * @deprecated This feature is now always on in dompdf 2.x
308          *
309          * @var bool
310          */
311         'enable_html5_parser' => true,
312     ],
313 ];