Wednesday, November 28, 2012

How to install wkhtmltopdf on CentOS 6.3

I was recently upgrading a server and I came across a problem that does not seem well documented on the internet. I have a CentOS 64bit Server running the latest version of WHM/cpanel. A client needed wkhtmltopdf installed for one of his websites so I thought I would show you how to install it on CentOS.

You can download wkhtmltopdf from this website: http://code.google.com/p/wkhtmltopdf/downloads/list

The first time I tried to install this I went with the latest version. At the time of writing this it was wkhtmltoimage-0.11.0_rc1 Linux Static Binary (amd64). However all I got when I tried to write a pdf was:

QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
Segmentation fault

This turned out to be because it was not a stable release so do not make the same mistake I made and download the latest release candidate. Rather download the stable version. At the time of writing this, the latest version is 0.99.

http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2

The following commands should get wkhtmltopdf working on cPanel server:

# wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
# tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
# mv wkhtmltopdf-amd64 /usr/bin/wkhtmltopdf
#chmod 777 /usr/bin/wkhtmltopdf

To test wkhtmltopdf run the following command:

# whktmltopdf http://www.google.com google.pdf

You should see a file in your directory called google.pdf. 

Hope this helped you save time. 

6 comments:

  1. Just used this and worked perfectly on CentOS 6. Thanks!

    ReplyDelete
  2. just change the command typo : whktmltopdf http://www.google.com google.pdf to wkhtmltopdf http://www.google.com google.pdf

    ReplyDelete
  3. Your this information blog is very informative thanks for share this blog.
    access Mp3skull in UK

    ReplyDelete
  4. Having a problem with wkhtmltopdf. I'm using it to take pdf snapshots of pages on a website that has a username/password page and i have used below syntax as per man page but its not working .
    wkhtmltopdf --username testuser --password ***** "html://xxxx.com" test.pdf

    ReplyDelete