Load multiple times with TCpdf in Yii structure

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)
{
    // check number of load this action :
    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):

// Include the main TCPDF library (search for installation path).
$dir=Yii::getPathOfAlias('webroot').'/my_library/tcpdf/examples/tcpdf_include.php';

require_once($dir);

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle('printing certificate');
$pdf->SetSubject('printing certificate');
$pdf->SetKeywords('PDF');

// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);


// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 061', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(FALSE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);


// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/far.php')) {
    require_once(dirname(__FILE__).'/lang/far.php');
    $pdf->setLanguageArray($l);
}

//$pdf->addTTFfont('/fonts/BZar.ttf', '', '', 32);
// ---------------------------------------------------------
// set font                                                          
$lg = Array();
$lg['a_meta_charset'] = 'UTF-8';
$lg['a_meta_dir'] = 'rtl';
$lg['a_meta_language'] = 'fa';
$lg['w_page'] = 'page';

// set some language-dependent strings (optional)
$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();                                                                        

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output("test.pdf", 'D');                                         // 
Yii::app()->end();
+4
source share
1 answer

.!

1:

.. render redirect .

2:

render . , , . ,

; -)

+1

All Articles