Convert HTML to PDF using free tools
Problem
You wish to convert a webpage given its URL to a PDF file. There are tools out there that can do that for free but also some very sophisticated that come to a cost.
Solution
One of the tools, is Open Source under the lisence LGPLv3 and its called wkhtmltopdf. It is a console application, running it in the terminal. It is dead simple to use, for example if someone wants to convert google.com to a PDF, the following will do the trick:
wkhtmltopdf http://google.com google.pdf
In addition, it can generate the PDF in grayscale by passing the -g argument as follows:
wkhtmltopdf -g http://google.com google.pdf
Output
The same tool can also generate an image of the webpage. Just use it like that:
wkhtmltoimage http://www.google.com google.png
Conclusion
In this post we saw how to easily generate a PDF document or an image from a given URL. The tool can be configured in plenty of ways by passing program arguments as explained in their documentation.