Install and enable WKHTMLTOPDF 0.12 on Ubuntu Server 14.04 or 16.04

WKHTMLTOPDF is a very handy binary tool to create PDF from HTML. I used it already in many projects and I am very happy with the results.

But the initial setup could be a little tricky if you don’t know your way around a Linux server. The following procedure works for me with WKHTMLTOPDF v.0.12.3 on Ubuntu Server 14.04 or 16.04:

  1. Go to WKHTMLTOPDF downloads page and copy URL for the linux stable version
  2. Download latest stable file from WHTMLTOPDF site and put it in a temporary folder e.g.:
    cd /tmp && wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-i386.tar.xz
  3. Extract with tar
    tar xf wkhtmltox-0.12.4_linux-generic-i386.tar.xz
  4. Move into /opt (or whatever path you prefer)
    mv /tmp/wkhtmltox /opt/
  5. Install dependencies. Ubuntu 14.04:
    apt-get install libXrender1 fontconfig libXext6
    Ubuntu 16.04:
    apt-get install libxrender1 fontconfig libxext6
  6. Create a symlink
    cd /usr/local/bin && ln -s /opt/wkhtmltox/bin/wkhtmltopdf

Important: if you get an error “cannot execute binary file: Exec format error” it means you need the 32bit version instead. Use the same procedure as above but replace “amd64” with “i386“.

If your dependencies were already automatically installed as dependencies from another package, you may want to mark them as manual. So if you remove that other package, they will not be listed as “unused”.

apt-mark manual libXrender1 fontconfig libXext6

Leave a Reply

Your email address will not be published. Required fields are marked *