hello,
i would like add mpdf in my project but not getting how to call the lib and class in controller. i m using version 3.3.5 and very new to cakephp please respond me asap.
hello,
i would like add mpdf in my project but not getting how to call the lib and class in controller. i m using version 3.3.5 and very new to cakephp please respond me asap.
This may help, a plugin for CakePHP and PDF
i had installed that but i wanna know how to configure this in controller . this is installed in vendors folder. how can i call or use them in controller to call my view
I beleave i need more information to help,
You should first load the plugin "config/bootstrap.php"
optinall edit “config/routes.php” for extension routing
Then configure in config/app.php or in controller
Configure::write('CakePdf', [
'engine' => 'CakePdf.WkHtmlToPdf',
'margin' => [
'bottom' => 15,
'left' => 50,
'right' => 30,
'top' => 45
],
'orientation' => 'landscape',
'download' => true
]);
end than you can use the engine (mPDF) you set in your view
Here is some code from my working app, so you can try:
in controller, name for example abc
public function initialize()
{
$this->loadComponent( ['viewClassMap' => ['pdf' => 'CakePdf.Pdf']]);
parent::initialize();
}
in some action/method, named xyz
{
$this->viewBuilder()->options([
'pdfConfig' => [
'engine' => 'CakePdf.Mpdf',
'orientation' => 'portrait',
'filename' => $filename,
'margin' => [
'bottom' => 0,
'left' => 0,
'right' => 0,
'top' => 0
],
'download' => true
]
]);
}
on the end of this action
$this->viewBuilder()->className(‘CakePdf.Pdf’);
and your *.ctp for this pdf is in:
Template/abc/ pdf /xyz.ctp