in Developer Experience

Running wkhtmltopdf in Vagrant (without X server)

Chances are you might need to run wkhtmltopdf on your server or in Vagrant environment (e.g. to overcome compatibility issue such as Cannot mix incompatible Qt library (version 0x50700) with this library (version 0x50701)). That way you need to be able to run it without an actual X server.

Solution is luckily pretty simple. You can fake your X server with xvfb which is virtual framebuffer X server. On Fedora that comes as xorg-x11-server-Xvfb package:

# dnf install xorg-x11-server-Xvfb -y

Afterwards you can prepend your actual command with xvfb-run:

$ xvfb-run --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf --quiet --page-size Letter --margin-top 0.75in --margin-right 0.75in --margin-bottom 0.75in --margin-left 0.75in --encoding UTF-8 source.html output.pdf

Subscribe for insights on Ruby, Rails, JavaScript, and more. Sent no more than once in 2 months.

Write a Comment