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

3 Answers 3


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.)

  • 1
    For posterity, this works on a Raspberry Pi, Raspbian Jessie as well. Thanks! Commented Mar 18, 2016 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
    Commented Aug 18, 2016 at 14:49
  • worked for me as well
    – Stefan
    Commented Oct 31, 2016 at 3:00
  • if you don't have the xvfb-run command in CentOS: yum install xorg-x11-server-Xvfb
    – kasimir
    Commented Aug 8, 2017 at 14:39
  • xvfb-run: error: Xvfb failed to start
    – tokam
    Commented Feb 24, 2019 at 18:40

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
    Commented Mar 26, 2015 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
    Commented Mar 26, 2015 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. Commented Mar 26, 2015 at 13:39
  • I still get the error
    – clarkk
    Commented Mar 26, 2015 at 13:41
  • 3
    Or just grab the latest linux generic binary from the website: wkhtmltopdf.org/downloads.html Commented Sep 27, 2016 at 7:46

on your command line type like this

export DISPLAY=:0 

then run your qt applications

  • 1
    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
    Commented Sep 9, 2016 at 8:21
  • Solved my problem on raspberry pi3, qt5.7.0, gui error: "QXcbConnection: Could not connect to display Aborted" .
    – mohammads
    Commented Jan 30, 2017 at 3:27
  • Doesn't work for me on Raspberry Pi3 I get an error: "QXcbConnection: Could not connect to display Aborted" Commented Nov 1, 2017 at 10:04
  • My raspberry Pi always boots in command line mode. Commented Nov 1, 2017 at 10:05
  • Solved my problem while trying to run OBS Studio from terminal. Thank you :-)
    – Mohamed
    Commented Mar 16, 2019 at 21:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .