Saturday, November 28, 2009

Creating PDF using wkhtmltopdf and Coldfusion

Coldfusion 8.0 does not support creating PDF from HTML pages which have Javascript that changes the look and feel, but in most of the cases you will have to create PDF for such documents only as JS is very common.

I looked on internet and found a really good free working solution, that works across MAC, LINUX and WINDOWS, wkhtmltopdf uses webkit rendering engine, and qt and works perfectly.

Steps

1. Download the required wkhtmltopdf for your operating system from http://code.google.com/p/wkhtmltopdf/
2. Use cfexecute command to call the program, you can either use and URL to a file path on your server and call it, below example uses a file on the server

windows - <cfexecute name="wkhtmltopdf.exe"
arguments="file:///d:/tmp/x.html d:\tmp\x.pdf"
timeout="120">
</cfexecute>

Linux - <cfexecute name="wkhtmltopdf"
arguments="/tmp/x.html /tmp/x.pdf"
timeout="120">
</cfexecute>

That is all what you need, it's a really good solution and works perfectly to create PDF, I hope Coldfusion introduces the use of JS in the next version of cfdocument tag. Ideally it should as CF on back uses iText Java free library which does everything.

2 comments:

Anonymous said...

I want to quote your post in my blog. It can?
And you et an account on Twitter?

Brijesh said...

@Anonymous, You can post it in your blog, I have no issue with that, I am not very regular with Twitter, twitter account @brijesradhika