I have an error trying to create a pdf HELP! :,c


(Jorge+) #1

Could you please help me? I am desperate and I have been a few days since I entered the world of Yii, and over these weeks I have run into many mistakes which make it difficult for me to work.
One of that for now I need to resolve is linked to the creation of pdf using mpdf.
I have already tried everything possible, and everything always ends in errors … one of them and the one that is causing me problems at the moment is:

"Fatal error: Trait 'Mpdf \ Strict' not found in C: \ xampp \ htdocs \ pdf2 \ protected \ vendor \ mpdf \ Mpdf.php on line 39"

I do not really understand why this error jumps me, and the truth very few ask about this error, and the truth is if I need someone at least to guide me in why this happens.
Next I leave the code that I am using for the creation of the pdf:

main.php:

 'ePdf' => array(
		        'class' => 'ext.yii-pdf.EYiiPdf',
		        'params' => array(
		            'mpdf'=> array(
		                'librarySourcePath' => 'application.vendor.mpdf.*',
		                'constants'=> array(
		                    '_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
		                ),
		                'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder
		                /*'defaultParams'     => array( // More info: http://mpdf1.com/manual/index.php?tid=184
		                    'mode'              => '', //  This parameter specifies the mode of the new document.
		                    'format'            => 'A4', // format A4, A5, ...
		                    'default_font_size' => 0, // Sets the default document font size in points (pt)
		                    'default_font'      => '', // Sets the default font-family for the new document.
		                    'mgl'               => 15, // margin_left. Sets the page margins for the new document.
		                    'mgr'               => 15, // margin_right
		                    'mgt'               => 16, // margin_top
		                    'mgb'               => 16, // margin_bottom
		                    'mgh'               => 9, // margin_header
		                    'mgf'               => 9, // margin_footer
		                    'orientation'       => 'P', // landscape or portrait orientation
		                )*/
		            )
					)),

DatosController.php: (the table of my db)

public function actionPdf($id)
	 {  
	    $model=$this->loadModel($id);
	    $mPDF1 = Yii::app()->ePdf->mpdf('utf-8','A4','','',15,15,35,25,9,9,'P');
	    $mPDF1->useOnlyCoreFonts = true;
	    $mPDF1->SetTitle("xxxxxxxxxx - Reporte");
	    $mPDF1->SetAuthor("");
	    $mPDF1->watermark_font = 'DejaVuSansCondensed';
	    $mPDF1->watermarkTextAlpha = 0.1;
	    $mPDF1->SetDisplayMode('fullpage');
	    $mPDF1->WriteHTML($this->renderPartial('pdf',array(
	            'model'=>$this->loadModel($id),
	        ),true));
	    $mPDF1->Output('Reporte_'.date('YmdHis'),'I');
	    exit;
	 }

in the AccesRule i have this:

public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('index','view'),
				'users'=>array('*'),
			),
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array('create','update'),
				'users'=>array('@'),
			),
			array('allow', // allow admin user to perform 'admin' and 'delete' actions
				'actions'=>array('admin','delete','create','update', 'index','view','Pdf', 'GenerarPdf'),
				'users'=>array('admin'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}

the rest of the code I used was to create a button that generates the pdf, that I did in the admin of the view of the table of my db, and an html file where the structure of the pdf to create is.
Please help, this is urgent, if someone in this forum can give me your support, I will thank you very much.
I clarify that the version of Yii that I am using is 1.1.6, and that of mpdf is 8.0.0


(Mehdi Achour) #2

Hi @Jorge1 and welcome to the forum!

It seems that the class autoloading is not working as expected, and it might be a problem with the extension you’re using.

Reading the requirements: https://github.com/Borales/yii-pdf#requirements and the commits history (no significant changes since 2013), it seems that you should be using mPDF 5.3 for this extension to work properly.

A LOT have changed in mPDF since that version, and v8 namespacing is different.


(Jorge+) #3

The truth is I do not know how to thank you partner for the support, if I had read in some forums that could be the verson of mPDF but many said that it should be used only the 6, but the 5 served me a lot.
Although it has not gone completely xD
At least I think I’m closer to it but it sends me this error:
“DataController can not find the requested view” pdf.html “.”
That pdf.html is what I plan to use for the structure of the pdf but it does not find it apparently.
I return to my code for the creation of the pdf and the view to generate:
DataController:
public function actionPdf($id)
{
$model=$this->loadModel($id);
$mPDF1 = Yii::app()->ePdf->mpdf(‘utf-8’,‘A4’,’’,’’,15,15,35,25,9,9,‘P’);
$mPDF1->useOnlyCoreFonts = true;
$mPDF1->SetTitle(“xxxxxxxxxx - Reporte”);
$mPDF1->SetAuthor("");
$mPDF1->watermark_font = ‘DejaVuSansCondensed’;
$mPDF1->watermarkTextAlpha = 0.1;
$mPDF1->SetDisplayMode(‘fullpage’);
$mPDF1->WriteHTML($this->renderPartial(‘pdf.html’,array(
‘model’=> $model,
),true));
$mPDF1->Output(‘Reporte_’.date(‘YmdHis’),‘I’);
exit;
}
pdf.html:

body { font-family: "Aparajita"; font-size: 10pt; } .ppal{ padding-top: 25px; }
Alumno <?php echo $model->datos->Nombre; ?> de la especialidad de <?php echo $model->datos->Especialidad; ?>
E. S. D.

$mpdf = new mPDF;

$mpdf->WriteHTML($html);

$mpdf->Output();

exit;
If you could tell me or someone who is stuck with this post, I would appreciate it, but anyway I thank you very much for your help at the beginning, partner, I hope you have a good day, night or tomorrow.
The truth thank you very much: D


(tri - Tommy Riboe) #4

Is pdf.html in views/data directory?


(Jorge+) #5

Yes my html file is in that directory


(tri - Tommy Riboe) #6

I don’t have time to verify but try .php extension instead of html