Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wkhtmltopdf extremely slow on Debian without X-server

Converting a pretty small HTML-file to PDF takes 2 seconds for my test enviroment (Windows 7). On the production web server the same file (Debian) needs 193 seconds.

The web server is being run with a managed hosting solution. They installed wkhtmltopdf and told me I had to use xvfb-run for it to work:

xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf "input_file.html" "output_file.pdf"

Now that I've complained that using this command it takes 193 seconds to generate a simple PDF, they say there is nothing they can do about it. Is that really so?

Edit: Somehow, my managed hosting support solved this after some nudging (now it takes 0.8 seconds). I think they might have recompiled the static wkhtmltopdf binaries or something. I now run wkhtmltopdf without xvfb-run.

like image 567
Vilhelm Avatar asked Jan 01 '26 12:01

Vilhelm


2 Answers

I assume you could leave the xvfb running

xvfb :1 -screen 0 640x480x16 &
DISPLAY=:1 wkhtmltopdf "input_file1.html" "output_file1.pdf"
DISPLAY=:1 wkhtmltopdf "input_file2.html" "output_file2.pdf"
DISPLAY=:1 wkhtmltopdf "input_file3.html" "output_file3.pdf"
  • I don't have experience with xvfb (I use x11vnc, Xnest and Xephyr with similar approaches like shown above).
  • Use an unused vtty (:1, :2, :3...)
  • perhaps there is a race condition now, in which case you might want to sleep .5 or something before launching wkhtmltopdf)
like image 129
sehe Avatar answered Jan 05 '26 18:01

sehe


wkhtmltopdf is going to be very slow, it is doing software rendering of the image in this case, since there is no GPU available.

An alternative is to go to http://wkhtmltopdf.org and download one of the static images. They can be run in true headless mode, and do not require an X server at all. This is still slow, but it has the advantage of having fewer moving parts.

like image 26
Jim Penny Avatar answered Jan 05 '26 16:01

Jim Penny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!