How to install wkhtmltopdf 0.12.1 on Ubuntu server?

In Ubuntu 16.04 and later wkhtmltopdf 0.12.2+ can be installed from the default Ubuntu repositories.

In Ubuntu 14.04, open the terminal and type:

sudo add-apt-repository ppa:ecometrica/servers
sudo apt-get update
sudo apt-get install wkhtmltopdf  

In Ubuntu 12.04, open the terminal and type:

sudo add-apt-repository ppa:pov/wkhtmltopdf
sudo apt-get update
sudo apt-get install wkhtmltopdf 

and one step after this is to reboot the server or else you will get the error: wkhtmltopdf: cannot connect to X server .


Steps:

  1. At first install xvfb serwer:

    sudo apt-get install xvfb
    
  2. Get needed version of wkhtmltopdf from http://wkhtmltopdf.org/downloads.html.

    For Ubuntu 14.04 64-bit:

    wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-trusty-amd64.deb
    
  3. Install wkhtmltopdf:

    sudo dpkg -i wkhtmltox-0.12.2.1_linux-trusty-amd64.deb
    

    Install dependency (if needed):

    sudo apt-get -f install
    
  4. Create symblic link in /usr/local/bin/:

    echo 'exec xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf "$@"' | sudo tee /usr/local/bin/wkhtmltopdf.sh >/dev/null
    sudo chmod a+x /usr/local/bin/wkhtmltopdf.sh