Installing wkhtmltopdf on Ubuntu 14.04 and 16.04
Installing wkhtmltopdf on Linux can be a bit tricky, especially for people who are not so familiar with *nix operating systems. There are various ways in which you can install wkhtmltopdf; use a package manager such as apt-get, compile from source, or download the pre-compiled binary file. We are going to be doing the latter in this tutorial.
Now the installation instructions for wkhtmltopdf have changed over the years, but as of this writing, the commands that you are about to see work for Ubuntu 14.04 and Ubuntu 16.04.
Installing wkhtmltopdf Dependencies
First, we need to install a couple of wkhtmltopdf dependencies.
apt-get install libfontconfig \
zlib1g \
libfreetype6 \
libxrender1 \
libxext6 \
libx11-6
Downloading & Extracting Archive
Then we will download and extract an archive containing the binary file. Be sure to update the link to use whichever version you prefer. You can find the links on the download page over at wkhtmltopdf.org.
curl -L -o wkhtmltopdf.tar.xz https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar -xf wkhtmltopdf.tar.xz
Moving Binary File & Permissions
Now we have a directory named wkhtmltox within our current working directory. This directory contains the binary file that we are looking for within the bin directory, namely wkhtmltopdf. We could just use that binary file from that directory as is, but we probably want to make wkhtmltopdf available throughout the system. To do that, we need to move it and give it permission to execute.
mv wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf
Testing wkhtmltopdf
You can test if wkhtmltopdf is working as intended by generating a PDF file with contents of google.com.
wkhtmltopdf https://www.google.com google.pdf
I will try to stay up to date with any changes, but these things change quite often. So if the above does not work out for you, please let me know in the comments.
8 comments on »Installing wkhtmltopdf on Ubuntu 14.04 and 16.04«
Thanks for this really well explained blog post. It worked like a charm.
Regards
Hello I have to do this on Ubuntu 16.04.3 LTS
instead of
thank you again :)
Thanks Marie, it worked.
I had trouble finding the exact last digit for different servers and found that omitting it worked in all scenarios I tried.
Thanks for the blog and thanks Marie for the last workaround !
So I was wondering from looking at the GitHub issue https://github.com/wkhtmltopdf/wkhtmltopdf/issues/3001 if this has been resolved and one can update libssl and wkhtmltopdf to the latest versions or if you still need to do this workaround?
Hello Sam,
It looks like the issue has been fixed. Although I haven’t tested it out, I went ahead and removed the fix from the post. Thanks for the heads up! :-)
I’m going to spin up some docker containers this weekend and see if it looks fixed. Would be nice not have to work around this issue anymore. Also thanks again for having this up, saved my bacon.
Sam