wkhtmltopdf – Convert webpage to PDF in Linux
Wkhtmltopdf is a command line utility that can be used to convert a webpage / html to PDF. Here is how it works…
Suppose I want to convert this website home page to a PDF document, I can fire up a terminal and run the
wkhtmltopdf command as follows.
$ wkhtmltopdf linuxandfriends.com linuxandfriends.pdf
This will download the linuxandfriends.com webpage, convert it to pdf and save it as linuxandfriends.pdf in the same directory from which the command was run.
To add a table of contents to the pdf document, use the
$ wkhtmltopdf -t linuxandfriends.com linuxandfriends.pdf
To get the pdf in landscape instead of portrait (which is the default) use
$ wkhtmltopdf -O landscape linuxandfriends.com linuxandfriends.pdf
wkhtmltopdf command line utility has a lot more options which can be viewed by running the command using
$ wkhtmltopdf --help
For example, you can add headers and footers to your pdf output, change the font in which text is rendered and so on.
wkhtmltopdf command line utility converts html to pdf using webkit (qtwebkit). This nifty tool is available for Windows, Linux and Mac OS X platforms. Download
wkhtmltopdf from its home page.