Powered By

Powered by Blogger

Minggu, 22 November 2009

Convert HTML to PDF [Linux]

There are numerous ways one can convert a web page (HTML) to PDF. Some using websites, a Firefox addon, but here is how to do it in Linux.


You could just, select "Print" (in Firefox: File > Print) and then select "Print to file" and the output "PDF".

But some pages with lots of CSS, javascript and so on won't be displayed correctly. For this, see the second method of converting webpages (html) to PDF (below).

Using wkhtmltopdf



To install wkhtmltopdf in Ubuntu, run the following command in a terminal:
sudo apt-get install wkhtmltopdf

Then, to convert a webpage to PDF, open a terminal and type this:
wkhtmltopdf http://www.webupd8.org webupd8.pdf

Replacing http://www.webupd8.org and webupd8.pdf with the website you want to convert to PDF / the name you desire for the converted PDF file.

The output of wkhtmltopdf is pretty good. Take a look:

wkhtmltopdf result


With wkhtmltopdf, you can disable the javascript on the page if you want, change the quality, orientation (portrait or landscape), and more. Too see everything wkhtmltopdf can do, type:

wkhtmltopdf --help

Tidak ada komentar:

Posting Komentar