Install wkhtmltopdf static binary on Ubuntu Server
Running wkhtmltopdf and wkhtmltoimage to create PDF files from HTML files on a Mac is easy and simple. When you need to install it on a non-mac production server a little bit of work is involved.
The Problem: Installing it simply via
sudo apt-get install wkhtmltopdf on Ubuntu will install a reduced functionality version which is probably not what you want. According to the manual the reduced functionality version does not include the following features.
- Printing more then one HTML document into a PDF file.
- Running without an X11 server.
- Adding a document outline to the PDF file.
- Adding headers and footers to the PDF file.
- Generating a table of contents.
- Adding links in the generated PDF file.
- Printing using the screen media-type.
- Disabling the smart shrink feature of webkit.
If you need any of these, then you need to setup the static version of wkhtmltopdf.
I just installed the wkhtmltopdf static binary successfully on Ubuntu 11.10 Oneiric on an Amazon EC2 instance with these steps:
Optional: Install Ubuntu on EC2
I used a 32bit Ubuntu image on EC2. Do a search for
oneiric i386 on the Ubuntu AMI Locator page and spin one up and connect to it.
Hint: the compilation will take hours even on a small instance. So be prepared if you want to use a t1.micro instance.
Now connect to your server via ssh.
apt-get update apt-get upgrade
Install the needed dependencies for wkhtmltopdf
apt-get build-dep libqt4-gui libqt4-network libqt4-webkit apt-get install openssl build-essential xorg git-core git-doc libssl-dev
Install the custom QT version for wkhtmltopdf
This will take quite some time. Grab a few coffees.
git clone git://gitorious.org/+wkhtml2pdf/qt/wkhtmltopdf-qt.git wkhtmltopdf-qt cd wkhtmltopdf-qt ./configure -nomake tools,examples,demos,docs,translations -opensource -prefix ../wkqt make -j3 make install cd ..
git clone git://github.com/antialize/wkhtmltopdf.git wkhtmltopdf cd wkhtmltopdf ../wkqt/bin/qmake make -j3 make install
The wkhtmltopdf binary should now be here:
/bin/wkhtmltopdf and you can use it like this:
wkhtmltopdf www.nytimes.com nytimes.pdf
Hope this works for you. For most of this i used the wkhtmltopdf Manual.
If you've read this far you might as well follow me on Twitter here.