Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a PDF from HTML?

Tags:

html

pdf

I am trying to generate a printable version of the HTML page, the printable version should have left pane and top pane stripped off. I tried to generate the printable version using JQuery, it has some layout issues while getting the stripped of content into the print preview screen(which is another stripped off HTML in pop up window).

Is there any ready made open source tool which converts HTML to PDF without much effort, because I have already lost quite a bit of time trying to explore in JQuery

I am using Grid 960 template layout

like image 842
Nrusingha Avatar asked Aug 22 '11 15:08

Nrusingha


2 Answers

When you have processed the html, wkhtmltopdf (Windows/Mac/Linux) can convert it to pdf. wkhtmltopdf is a cross-platform, open source (LGPLv3) command line tool to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These run entirely "headless" and do not require a display or display service.

wkhtmltopdf can be downloaded from the official wkhtmltopdf website. It is also in the default repositories of most common Linux distributions.

Examples

Convert a remote HTML file to PDF:

wkhtmltopdf http://www.google.com example.pdf

Convert a local HTML file to PDF:

wkhtmltopdf example.html example.pdf

wkhtmltopdf usage You can also display the wkhtmltopdf help locally by running wkhtmltopdf -H.

like image 153
David Andersson Avatar answered Oct 20 '22 22:10

David Andersson


why not just use a print stylesheet, and let your users print to PDF if they want to?

http://www.alistapart.com/articles/goingtoprint/

like image 38
Dan Avatar answered Oct 20 '22 23:10

Dan