]> BookStack Code Mirror - website/commitdiff
Added weasyprint docker PDF command example
authorDan Brown <redacted>
Sun, 12 Jan 2025 12:18:56 +0000 (12:18 +0000)
committerDan Brown <redacted>
Sun, 12 Jan 2025 12:18:56 +0000 (12:18 +0000)
content/docs/admin/pdf-rendering.md

index ae2324eafde46abb7682795acfdc70e7231354d8..07faa23a989b576b89d6d1e4e82382fffcc9bc17 100644 (file)
@@ -70,6 +70,64 @@ This example uses [weasyprint](https://doc.courtbouillon.org/weasyprint/stable/)
 EXPORT_PDF_COMMAND="weasyprint {input_html_path} {output_pdf_path}"
 ```
 
+#### Example: Weasyprint via Docker
+
+This example also uses [weasyprint](https://doc.courtbouillon.org/weasyprint/stable/) to generate PDF exports,
+but via a docker container to help isolate the PDF generation process. This also allows the PDF generation
+to be performed remotely on other systems if needed since communication with BookStack is performed over HTTP
+using curl. This uses the [4teamwork/weasyprint](https://github.com/4teamwork/weasyprint-docker) and [caddy](https://caddyserver.com/)
+docker containers.
+
+**Considerations:**
+
+- Curl must be installed on the host system.
+- This container setup provides extra levels of isolation, but this does not assure fully secure sandboxing.
+- If using on a different host, you may need to consider limiting access or adding auth to avoid exposing to the general web.
+
+<details>
+<summary>Docker Compose Setup</summary>
+
+Save the below as `docker-compose.yml` then run `docker compose up -d` within the same directory
+to start up the containers. 
+
+This sets up the `4teamwork/weasyprint` container on its own isolated network, which is then exposed/proxied
+via the caddy proxy container on port 3000 to the host.
+
+```yml
+services:
+  weasyprint:
+    image: 4teamwork/weasyprint:latest
+    networks:
+      - weasy-net
+    restart: always
+  proxy:
+    image: caddy:2.9-alpine
+    command: caddy reverse-proxy --from http://127.0.0.1:3000 --to http://weasyprint:8080 
+    ports: 
+      - 127.0.0.1:3000:3000
+    networks: 
+      - weasy-net
+      - proxy
+    restart: always
+
+networks:
+  weasy-net:
+    driver: ipvlan
+    internal: true
+  proxy:
+    driver: bridge
+    internal: false
+```
+
+</details>
+
+```bash
+# Export to PDF by calling the Weasyprint docker service using curl.
+# This will likely need altering if running on non-unix systems,
+# or if running on an external host, or when using a different port.
+EXPORT_PDF_COMMAND='EXPORT_HTML={input_html_path}; curl -F "html=@$EXPORT_HTML" http://127.0.0.1:3000 -o {output_pdf_path}'
+```
+
 ---
 
 ### Using wkhtmltopdf