Use TCPDF in Magento

Why you going to use TCPDF library in magento since magento zend have pdf library ?
because you can make HTML to PDF in tcpdf but not directly with zendframwork.

Here is how you can do it very easy

Download tcpdf library
Create a directory TCPDF in magento’s lib directory in magento root and copy all tcpdf files in that directory /lib/TCPDF
rename tcpdf.php to TCPDF.php
open TCPDF.php and change class name to class TCPDF_TCPDF {
That’s it.
Now you can call tcpdf library from anywhere in magento like this

  $tcpdf = new TCPDF_TCPDF();

//your htmls here
$html = '

hello world

'; $tcpdf->AddPage(); $tcpdf->writeHTML($html, true, false, true, false, ''); $tcpdf->lastPage(); $tcpdf->Output('report_per_route_'.time().'.pdf', 'I');

or save pdf file in var/report

$fn = Mage::getBaseDir('base').'/var/report/report_'.time().'.pdf';
$tcpdf->Output($fn, 'F');

Posted

in

by