Integrate HTML2PDF script into cakePHP as vendor application

Posted Under: PHP

0 Flares 0 Flares ×

Vendor function is amazing feature in cakePHP. You can use the vendors directory to keep third-party libraries in cakePHP. When you want to use any ready to use PHP classes or scripts which are not written as per cakePHP convention then you can use vendors directory to keep those scripts. The basic idea is that you can access classes you’ve placed in the vendors directory using Cake’s vendor() function. ,

In one of our project we were needed to create PDF file on the fly. Nowadays is it very common need in every project so this time we targeted to have perfect solution which can cater this common need of most of projects. We explored available options and we found a good script called HTML2PDF. This script is 100% FREE for commercial AND non-commercial use. HTML2PDF is a simple HTML to PDF / PostScript tool which can quickly and easily convert HTML pages into PDF and PostScript files. It renders URLs of (dynamic) (x)html pages including CSS to PDF and PostScript files on the fly.

Features covered

·         Generate PDF from HTML

·         Customize your PDF by providing media, type etc.

·         Automatically detect CSS information from the screen

·         You are able to give water mark to all the pages in the pdf.

·         You can also set the PDF page size

We found this is the best available solution for us. But this script is not written as per CakePHP convention and we wanted to integrate it into cakePHP framework. So we decided to take this script as vendor script into cakePHP. We wrote a wrapper class to use this script into cakePHP application and it worked perfectly. Now we just need to include this vendor script into the controller where we want to use this script and use this script feature through our written wrapper class.


Beside its good points there are some limitation with this script as well, below are which we encountered during integrating it into our projects.

·         It only works on HTML elements include images but does not work when page contains Flash elements or any other custom objects such as java applets, Active X controls etc… 

·         It support (included in default installation of the script) almost all fonts but still if any fond it not in its font directory than it will work but the formatting can be an issue. Although they provide alternative font setting so in case any font is not available than alternative font will be use to format the text.

·         If your HTML page is big than it requires you to extend you memory limit otherwise it will give error.

To know more about this HTML2PDF library click here 
Rightway has handsome experience in developing this kind of functionality. So feel free to contact us if you have this kind of requirement.

Posted by : Abhishek Agarwal Date : June 2, 2009

Abhishek Agarwal is Co-founder and CEO of Rightway Solution and Leads Business Development and Marketing Initiatives.

Comments are closed.

0 Flares Facebook 0 Twitter 0 LinkedIn 0 Google+ 0 0 Flares ×