From: Dan Brown Date: Sun, 12 Jan 2025 12:18:56 +0000 (+0000) Subject: Added weasyprint docker PDF command example X-Git-Url: http://source.bookstackapp.com/website/commitdiff_plain/89b82a563474f76abc7cb169b96bfb39a0986d7d Added weasyprint docker PDF command example --- diff --git a/content/docs/admin/pdf-rendering.md b/content/docs/admin/pdf-rendering.md index ae2324e..07faa23 100644 --- a/content/docs/admin/pdf-rendering.md +++ b/content/docs/admin/pdf-rendering.md @@ -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. + +
+Docker Compose Setup + +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 +``` + +
+ +```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