php - in yii2 on using TCPDF library i am getting "Failed to load PDF document." error
I am trying to generate example pdf file as it is shown here: https://packagist.org/packages/hbalkhi/yii2-pdf.
output ---> this is the out put.
myController
public function actionTcpdf()
{
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
Yii::$app->response->headers->add('Content-Type','application/pdf');
return $this->render('tcpdf');
}
View
<?php
/**
* @copyright Copyright ©2014 Giandomenico Olini
* @company Gogodigital - Wide ICT Solutions
* @website http://www.gogodigital.it
* @package yii2-tcpdf
* @github https://github.com/cinghie/yii2-tcpdf
* @license GNU GENERAL PUBLIC LICENSE VERSION 3
* @tcpdf library 6.0.075
* @tcpdf documentation http://www.tcpdf.org/docs.php
* @tcpdf examples http://www.tcpdf.org/examples.php
*/
// echo "12345";
// exit();
// Load Component Yii2 TCPDF
\Yii::$app->get('tcpdf');
// 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->SetAuthor('Gogogital.it');
$pdf->SetTitle('Yii2 TCPDF Example');
$pdf->SetSubject('Yii2 TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// 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 header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, 'Yii2 TCPDF Example', 'Gogodigital - Wide ICT Solutions | gogodigital.it', array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
// 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(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//
this is the view code. I have been echoing at different places and it works fine but when i echo in view where m making a new variable for pdf in start the echo doesn't comes but the error.