Tuesday, April 11, 2006

Just 5 lines to generate dynamic PDF in php

Normally we don't care about technologies until we need them and later wondered ...that's great. The same happened to me today. Asked to generate pdf dynamically and after googling for few minutes, i got hold of perfect library; perfect because it doesn't require you to install modules and change configuration. If you want to use PDF functions listed in the php manual, then you would have to install the extension. However this great site http://www.ros.co.nz/pdf/ has the perfect solution for dynamic pdf creation.

Just download the zip file from the site. Unzip to some folder in your document root.
Create a new file and add the following code to see the effect in a second. You will also find some example in the readme.pdf, packed in the zip file. You can also have html tags in the passed string. Isn't that 5 lines of code amazing?
$doc = "Hello World!!!!";
include (
'class.ezpdf.php');
$pdf =& new Cezpdf();
$pdf->selectFont('./fonts/Helvetica.afm');
$pdf->ezText($doc,10);
$pdf->ezStream();
?>

No comments: