Skip to content


How to convert HTML pages to PDF in Ubuntu Linux

Linux

A really neat tool I was introduced to a few days back is wkhtmltopdf, a freely distributed tool that allows you to convert HTML pages into PDF documents. This is not something I’ve found a lot of use for too often, but when I’ve needed it it’s been a life saver. Let’s take a look at how to set it up and use it.

The installation of wkhtmltopdf is a lot less difficult that trying to pronounce the name of the project. As the project is not yet distributed as installable binaries you will need to compile it.

Requirements:

- QT 4.4 or above
- CMake 1.6 or above
- Subvertion

On Ubuntu do the following to install the tools required to compile:

# sudo apt-get update
# sudo apt-get install libqt4-dev qt4-dev-tools build-essential cmake

Now check out the latest code for the application from the project’s SVN repositories.

# svn checkout http://wkhtmltopdf.googlecode.com/svn/trunk/ wkhtmltopdf

Time to build and compile it:

# cd wkhtmltopdf
# cmake -D CMAKE_INSTALL_PREFIX=/usr .
# make
# sudo make install

Once you are done with the previous steps using wkhtmltopdf is a piece of cake. To convert a web page from HTML to PDF all you need to do is to run the following command:

# wkhtmltopdf http://www.simplehelp.net simplehelp.pdf

The previous command will access the website http://www.simplehelp.net and create a PDF document with its contents. You obviously need a working Internet connection for this to work. You can also modify the above command slightly to convert an HTML file stored on your computer into a PDF document:

# wkhtmltopdf /home/calvin/sevenacross.html sevenacross.pdf

Pretty neat stuff, eh! wkhtmltopdf has several options allowing you to make the PDF document in Portrait mode or Landscape, and so on. Visit the project’s website for more info on it.

Posted in Linux.

Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

 

You can always opt out of this email subscription at any time.

One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Continuing the Discussion

  1. Convertir HTML a PDF en Ubuntu 9.10 Karmik Koala en Notas de Samuel Giubi linked to this post on November 10, 2009

    [...] Fuente. Comparte y Disfruta!: [...]



Some HTML is OK

or, reply to this post via trackback.