In this tip we will see how to use the command line (terminal) to convert web pages to PDF or PS (postscript) files under Ubuntu or Debian. This is possible with the help of Wkhtmltopdf, which is an excellent tool for converting HTML pages to PDF/PS.

Install first the Wkhtmltopdf command line tool using this command:

sudo apt-get install wkhtmltopdf

To convert a web page to PDF, run this command from the Terminal:

wkhtmltopdf URL output.pdf

Replace URL and output.pdf with your own details. Here is an example:

wkhtmltopdf http://www.upubuntu.com upubuntu.pdf

To convert a web page to PS (postscript), issue this command:

wkhtmltopdf http://www.upubuntu.com upubuntu.ps

For more conversion options, use this command:

wkhtmltopdf http://www.upubuntu.com upubuntu.pdf -n  -B 12mm -L 14mm -R 10mm

You can find all conversion parameters by running this command:

man wkhtmltopdf

To convert a local HTML file to PDF/PS, use one of these commands:

wkhtmltopdf page.html output.pdf
wkhtmltopdf page.html output.ps

That's it!

Post a Comment