Vilhelm
Vilhelm

Reputation: 148

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.

Upvotes: 3

Views: 4724

Answers (2)

Jim Penny
Jim Penny

Reputation: 81

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.

Upvotes: 1

sehe
sehe

Reputation: 393567

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)

Upvotes: 2

Related Questions