How to convert HTML pages to PDF in Ubuntu Linux

This tutorial will show you exactly how to convert a web page (HTML) to a PDF document in Linux, using free & open source software.

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 https://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.

Looking for more Linux tips and tricks? We’ve got you covered! :)


If this article helped you, I'd be grateful if you could share it on your preferred social network - it helps me a lot. If you're feeling particularly generous, you could buy me a coffee and I'd be super grateful :)

buy a coffee for simplehelp.net


Home » Linux » How to convert HTML pages to PDF in Ubuntu Linux

1 thought on “How to convert HTML pages to PDF in Ubuntu Linux”

Leave a Comment

Your email address will not be published.