I work with Tcpdf in the Yii framework (just), when I created a new Tcpdf in my opinion to export the file, it caused my load load two or three times (I checked it with a counter in my action) and finally it worked and gave me my pdf file.
I do not want this action to load several times, because in the action I change some attributes according to some rules, and these rules will change after the first start of the controller.
this problem is in the host and in my local (xammp) correct operation (my server is Linux)
my action:
public function actionPrint_diploma($id)
{
if(isset(Yii::app()->session['counter'])&&Yii::app()->session['counter']>=0)
Yii::app()->session['counter']=Yii::app()->session['counter']+1;
else
Yii::app()->session['counter']=0;
$this->render('coach_certificate');
}
my view (coach_certificate.php):
$dir=Yii::getPathOfAlias('webroot').'/my_library/tcpdf/examples/tcpdf_include.php';
require_once($dir);
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle('printing certificate');
$pdf->SetSubject('printing certificate');
$pdf->SetKeywords('PDF');
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 061', PDF_HEADER_STRING);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(FALSE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (@file_exists(dirname(__FILE__).'/lang/far.php')) {
require_once(dirname(__FILE__).'/lang/far.php');
$pdf->setLanguageArray($l);
}
$lg = Array();
$lg['a_meta_charset'] = 'UTF-8';
$lg['a_meta_dir'] = 'rtl';
$lg['a_meta_language'] = 'fa';
$lg['w_page'] = 'page';
$pdf->setLanguageArray($lg);
$pdf->AddPage();
$pdf->SetFont('freeserif', '', 10);
$pdf->SetAbsXY(305,50);
$html = Yii::app()->session['counter'];
$pdf->writeHTML($html, true, false, true, true,'C');
$pdf->lastPage();
$pdf->Output("test.pdf", 'D');
Yii::app()->end();