My dear friends today my aim is to devolope a predefined pdf file using Yii framework and tcpdf..
It is easy.Come with me.I will show you the way.
Step 01 :
Download the latest tcpdf using the below link.
http://sourceforge.net/projects/tcpdf/files/
Step 02 :
Now unzip the files to extension folder in your yii project.
It is under \protected\extensions directory.
Now your folder should be like this
It is easy.Come with me.I will show you the way.
Step 01 :
Download the latest tcpdf using the below link.
http://sourceforge.net/projects/tcpdf/files/
Step 02 :
Now unzip the files to extension folder in your yii project.
It is under \protected\extensions directory.
Now your folder should be like this
Step 03 :
Now you need a controller file.Copy below set of codes and save it as mycontroller.php in \protected\controllers directory.
<?php
class mycontroller extends Controller{
public function actionGeneratePdf() {
$path = Yii::app()->basePath;//this is how we call the pase path in Yii.
require_once($path.'/extensions/tcpdf/tcpdf.php');
$pdf = new TCPDF();
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 001');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetHeaderData('', 0, 'Information', 'All data in one');
$pdf->setHeaderFont(Array('helvetica', '', 8));
$pdf->setFooterFont(Array('helvetica', '', 6));
$pdf->SetMargins(10, 18, 15);
$pdf->SetHeaderMargin(5);
$pdf->SetFooterMargin(10);
$pdf->SetAutoPageBreak(TRUE, 0);
$pdf->SetFont('dejavusans', '', 7);
$pdf->AddPage();
$pdf->writeHTML("<span>Hello My dear Manuja!</span>", true, false, true, false, '');
$pdf->LastPage();
$pdf->Output("My.pdf", "I");
}
}
?>
Step 04 :
That is all.Now go to web browser addaress bar and type
http://localhost/yii/myyii/index.php?r=my/GeneratePdf
Yow will get the below output....
That is all..be happy...