Problem with wkhtmltopdf #1694

Closed
opened 2026-02-05 01:38:25 +03:00 by OVERLORD · 7 comments
Owner

Originally created by @techauthoruk on GitHub (Apr 30, 2020).

Hi

Having a problem using wkhtmltopdf for generating my pdfs. Originally, I was using the default dompdf setup, which worked fine, but the output (particularly of tables) wasn't very good. So I installed wkhtmltopdf on my server (running Ubuntu 18.04) and copied it to the Bookstack directory (which is exactly what I did on my other install on a different server - running CentOS 8.1).

I changed the permissions for wkhtmltopdf to root:root 0750 (same as my other server), but when I try to create a pdf I get:

An Error Occurred
An unknown error occurred

Instead I tried adding the path to wkhtmltopdf in the .env file, but same result.

Anyone any suggestions how to sort this?

Thanks

Mark

Originally created by @techauthoruk on GitHub (Apr 30, 2020). Hi Having a problem using wkhtmltopdf for generating my pdfs. Originally, I was using the default dompdf setup, which worked fine, but the output (particularly of tables) wasn't very good. So I installed wkhtmltopdf on my server (running Ubuntu 18.04) and copied it to the Bookstack directory (which is exactly what I did on my other install on a different server - running CentOS 8.1). I changed the permissions for wkhtmltopdf to root:root 0750 (same as my other server), but when I try to create a pdf I get: An Error Occurred An unknown error occurred Instead I tried adding the path to wkhtmltopdf in the .env file, but same result. Anyone any suggestions how to sort this? Thanks Mark
Author
Owner

@ssddanbrown commented on GitHub (Apr 30, 2020):

@techauthoruk You can follow the debugging guide to gain more detail on the error:
https://www.bookstackapp.com/docs/admin/debugging/

Sometimes I have had to run wkhtml through xvfb-run before since WKHTML sometimes needs an X server depending on version and system, But the logs should have some clues as to what's happening.

@ssddanbrown commented on GitHub (Apr 30, 2020): @techauthoruk You can follow the debugging guide to gain more detail on the error: https://www.bookstackapp.com/docs/admin/debugging/ Sometimes I have had to run wkhtml through `xvfb-run` before since WKHTML sometimes needs an X server depending on version and system, But the logs should have some clues as to what's happening.
Author
Owner

@techauthoruk commented on GitHub (May 1, 2020):

@ssddanbrown

Thanks for that. This is the error detail:

RuntimeException
The exit status code '126' says something went wrong: stderr: "sh: 1: /var/www/bookstack/wkhtmltopdf: Permission denied " stdout: "" command: /var/www/bookstack/wkhtmltopdf --lowquality --print-media-type '/tmp/knp_snappy5eab9d91b32850.22533742.html' '/tmp/knp_snappy5eab9d91b331a7.99555749.pdf'.

I don't understand the permission denied error, as all the permissions look ok as I previously mentioned. In the laravel log file I see this several times:

command: /var/www/bookstack/wkhtmltopdf --lowquality --print-media-type '/tmp/knp_snappy5e9e59e5d3bcf1.53933425.html' '/tmp/knp_snappy5e9e59e5d3c652.35544182.pdf'. {"userId":1,"exception":"[object] (RuntimeException(code: 1): The exit status code '1' says something went wrong:
stderr: "The switch --print-media-type, is not support using unpatched qt, and will be ignored.QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-www-data'
qt.qpa.screen: QXcbConnection: Could not connect to display
Could not connect to any X display.

So is this what you mentioned about running wkhtmltopdf through xvfb-run? How would I do that?

Many thanks for your asssitance.

Mark

@techauthoruk commented on GitHub (May 1, 2020): @ssddanbrown Thanks for that. This is the error detail: RuntimeException The exit status code '126' says something went wrong: stderr: "sh: 1: /var/www/bookstack/wkhtmltopdf: Permission denied " stdout: "" command: /var/www/bookstack/wkhtmltopdf --lowquality --print-media-type '/tmp/knp_snappy5eab9d91b32850.22533742.html' '/tmp/knp_snappy5eab9d91b331a7.99555749.pdf'. I don't understand the permission denied error, as all the permissions look ok as I previously mentioned. In the laravel log file I see this several times: command: /var/www/bookstack/wkhtmltopdf --lowquality --print-media-type '/tmp/knp_snappy5e9e59e5d3bcf1.53933425.html' '/tmp/knp_snappy5e9e59e5d3c652.35544182.pdf'. {"userId":1,"exception":"[object] (RuntimeException(code: 1): The exit status code '1' says something went wrong: stderr: \"The switch --print-media-type, is not support using unpatched qt, and will be ignored.QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-www-data' qt.qpa.screen: QXcbConnection: Could not connect to display Could not connect to any X display. So is this what you mentioned about running wkhtmltopdf through `xvfb-run`? How would I do that? Many thanks for your asssitance. Mark
Author
Owner

@techauthoruk commented on GitHub (May 1, 2020):

@ssddanbrown

Problem solved - I found a tutorial explaining how to set up xvfb, and wkhtmltopdf now works with Bookstack

Thanks for the help - I will close this issue now.

Mark

@techauthoruk commented on GitHub (May 1, 2020): @ssddanbrown Problem solved - I found a tutorial explaining how to set up xvfb, and wkhtmltopdf now works with Bookstack Thanks for the help - I will close this issue now. Mark
Author
Owner

@ssddanbrown commented on GitHub (May 1, 2020):

@techauthoruk Ah, great, glad you got it working!

@ssddanbrown commented on GitHub (May 1, 2020): @techauthoruk Ah, great, glad you got it working!
Author
Owner

@gor181 commented on GitHub (Mar 4, 2022):

Just a note to anyone who is having issues with this. The setup is as follows:

  • Install Wkhtmltopdf from the official source
  • Follow the step 1 & Step 2 from this guide
  • Edit the .env file and set the following:
WKHTMLTOPDF="/usr/bin/xvfb-run wkhtmltopdf"
ALLOW_UNTRUSTED_SERVER_FETCHING=true

Please understand the security implications of the ALLOW_UNTRUSTED_SERVER_FETCHING option before using.

@gor181 commented on GitHub (Mar 4, 2022): Just a note to anyone who is having issues with this. The setup is as follows: - Install Wkhtmltopdf from the [official source ](http://wkhtmltopdf.org/downloads.html) - Follow the step 1 & Step 2 from [this guide](https://coderwall.com/p/tog9eq/using-wkhtmltopdf-and-an-xvfb-daemon-to-render-html-to-pdf) - Edit the .env file and set the following: ``` WKHTMLTOPDF="/usr/bin/xvfb-run wkhtmltopdf" ALLOW_UNTRUSTED_SERVER_FETCHING=true ``` **Please [understand the security implications](https://www.bookstackapp.com/docs/admin/security/#server-side-requests) of the `ALLOW_UNTRUSTED_SERVER_FETCHING` option before using.**
Author
Owner

@ssddanbrown commented on GitHub (Mar 4, 2022):

Updated the above with a note of the security implications of using the displayed options.

@ssddanbrown commented on GitHub (Mar 4, 2022): Updated the above with a note of the security implications of using the displayed options.
Author
Owner

@Mohamed-sobhi95 commented on GitHub (Nov 5, 2023):

How to enable wkhtmltopdf in the docker compose version

@Mohamed-sobhi95 commented on GitHub (Nov 5, 2023): How to enable wkhtmltopdf in the docker compose version
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#1694