How to run wkhtmltopdf headless?!

Installation on Debian Whezzy

apt-get install wkhtmltopdf


wkhtmltopdf --title "$SUBJECT" -q $SOURCEFILE $OUTPUTFILE


QXcbConnection: Could not connect to display

This is a bug, and the fix hasn't been brought to the Debian repositories. Quoting ashkulz (who closed the bug report) :

You're using the version of wkhtmltopdf in the debian repositories, which does not support running headless.

So you can either...

  • 1
    If you do not want to build wkhtmltopdf from source, you might want to try phantomjs with: phantomjs /usr/share/doc/phantomjs/examples/rasterize.js $url $pdf. – ysdx Mar 26 '15 at 13:12
  • Have now downloaded the source to /var/bin/wkhtmltopdf.. cd /var/bin/wkhtmltopdf && scripts/build.py wheezy-amd64 => -bash: scripts/build.py: Permission denied – clarkk Mar 26 '15 at 13:37
  • @clarkk You shouldn't download the source to /var/bin. Take it to your home directory and follow the instructions in the INSTALL.md file, for your distribution. – John WH Smith Mar 26 '15 at 13:39
  • I still get the error – clarkk Mar 26 '15 at 13:41
  • 1
    Or just grab the latest linux generic binary from the website: wkhtmltopdf.org/downloads.html – marcovtwout Sep 27 '16 at 7:46

There is a more easy way to make John WH Smith solution.

Just install xvfb from apt and then, you can run:

xvfb-run wkhtmltopdf

(just put xvfb-run before any wkhtmltopdf command.)

  • For posterity, this works on a Raspberry Pi, Raspbian Jessie as well. Thanks! – slightlynybbled Mar 18 '16 at 4:25
  • Also if you get xvfb-run: error: xauth command not found then just sudo apt-get install xauth and try again! – MediaVince Aug 18 '16 at 14:49
  • worked for me as well – Stefan Oct 31 '16 at 3:00
  • if you don't have the xvfb-run command in CentOS: yum install xorg-x11-server-Xvfb – kasimir Aug 8 '17 at 14:39
  • xvfb-run: error: Xvfb failed to start – tokam Feb 24 at 18:40

on your command line type like this

export DISPLAY=:0 

then run your qt applications

  • this may not be the right answer for the question at large, but I came here from google for a different similar problem that this solved. – plod Sep 9 '16 at 8:21
  • Solved my problem on raspberry pi3, qt5.7.0, gui error: "QXcbConnection: Could not connect to display Aborted" . – mohammads Jan 30 '17 at 3:27
  • Doesn't work for me on Raspberry Pi3 I get an error: "QXcbConnection: Could not connect to display Aborted" – abhishek77in Nov 1 '17 at 10:04
  • My raspberry Pi always boots in command line mode. – abhishek77in Nov 1 '17 at 10:05
  • Solved my problem while trying to run OBS Studio from terminal. Thank you :-) – Sangimed Mar 16 at 21:18

protected by Community Jul 15 '17 at 19:16

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.