]> BookStack Code Mirror - website/blob - content/docs/admin/pdf-rendering.md
Made doc updates for v24.10 release
[website] / content / docs / admin / pdf-rendering.md
1 +++
2 title = "PDF Rendering"
3 description = "Options to configure PDF rendering within BookStack"
4 date = "2017-01-22"
5 type = "admin-doc"
6 +++
7
8 By default BookStack uses [dompdf](https://github.com/dompdf/dompdf) to export pages as PDF documents. The benefit of using dompdf is that it doesn't require any additional installation or setup but the rendering capabilities are somewhat limited.
9
10 As an alternative you can instead define a command to make use of external PDF rendering options that may provide more capabilities.
11
12 {{<toc>}}
13
14 ---
15
16 ### Export Page Size
17
18 By default PDF exports are generated at an A4 size. If you'd prefer exports to be generated at "US Letter" standard sizes
19 you can specify this within your `.env` like so:
20
21 ```bash
22 # US Letter
23 EXPORT_PAGE_SIZE=letter
24 ```
25
26 ---
27
28 ### PDF Export Command
29
30 Instead of using the default PHP-based default PDF rendering system, you can define a command for BookStack to use when generating
31 a PDF. This enables flexibility in what program is used to create PDF exports.
32 The command is set via a `EXPORT_PDF_COMMAND` option in your `.env` file, which can use the following placeholders:
33
34 - `{input_html_path}` - Path to a file where BookStack will provide HTML to convert.
35 - `{output_pdf_path}` - Path to a file where the command should output its PDF result.
36
37 Here's an example value for this option using these placeholders:
38
39 ```bash
40 EXPORT_PDF_COMMAND="/scripts/convert.sh {input_html_path} {output_pdf_path}"
41 ```
42
43 Below you can find some examples using this for specific PDF generation options.
44
45 **Timeout**
46
47 By default BookStack will wait for 15 seconds before reaching a timeout, at which point it'd consider the export process as failed, but this can be configured like so:
48
49 ```bash
50 # Allow 30 seconds for the export process instead of the default 15
51 EXPORT_PDF_COMMAND_TIMEOUT=30
52 ```
53
54 **Considerations**
55
56 - Security is a significant concern for this option and process. Input HTML will include user-editable data, and is not assured to be trustworthy & safe. Ideally, any networking or filesystem access would be disabled/prevented during conversion.
57 - BookStack will attempt to embed required images into the HTML data as base64 data URIs to avoid external fetching.
58 - BookStack will embed CSS styling into the HTML data.
59 - Use of this option requires running a process from PHP, which can be considered risky and may potentially be blocked by configuration, environment and/or systems like SELinux by default.
60 - BookStack sets a default timeout of 15 seconds for this command to return, unless altered as shown above.
61 - BookStack will use the return status code of the command as an indicator of failure/success, while also checking that the output PDF was written to.
62
63 #### Example: Weasyprint Command Option
64
65 **Warning:** This is option is not considered secure due to potential filesystem/network access.
66
67 This example uses [weasyprint](https://doc.courtbouillon.org/weasyprint/stable/) to generate PDF exports.
68
69 ```bash
70 EXPORT_PDF_COMMAND="weasyprint {input_html_path} {output_pdf_path}"
71 ```
72
73 ---
74
75 ### Using wkhtmltopdf
76
77 **Note:** As of BookStack v24.05 this option is considered deprecated, due to the diminishing support of wkhtmltopdf.
78 You can instead use the more flexible [PDF Export Command](#pdf-export-command) option detailed above.
79
80 Pre-compiled binaries for wkhtmltopdf can be found on the downloads page of [their website](http://wkhtmltopdf.org/downloads.html).
81 BookStack will check for a file named `wkhtmltopdf` at the base folder of a BookStack install. If found it will use that to render PDF exports. 
82 If that does not exist it will check for a `WKHTMLTOPDF` variable in the `.env` file. 
83 You can use the below variable in your `.env` file to set an alternate location to wkhtmltopdf:
84
85 ```bash
86 WKHTMLTOPDF=/home/user/bins/wkhtmltopdf
87 ```
88
89 If neither of those exist, or if the below mentioned security option is not enabled, the default dompdf renderer will be used instead.
90
91 **Note:** As of BookStack v21.08 the `ALLOW_UNTRUSTED_SERVER_FETCHING` must also be set to `true` for wkhtmltopdf to be enabled, without this dompdf will be used instead. 
92 This change was made for security since, in many cases, wkhtmltopdf will perform fetches to external URLs which may be defined by users.
93 You should only enable the below option in environments where users & visitors are trusted.
94
95 ```bash
96 ALLOW_UNTRUSTED_SERVER_FETCHING=true
97 ```
98
99 [See our security page for more detail regarding this option](/docs/admin/security/#server-side-requests).