I found this similar post but I am still having trouble: How to get CakePdf to work in CakePHP 3.x?
Can anyone help me figure out what I'm doing wrong or what I'm missing?
// config/bootstrap.php
Plugin::load('CakePdf', ['bootstrap' => true, 'routes' => true]);
Configure::write('CakePdf', [
'engine' => 'CakePdf.WkHtmlToPdf',
'binary' => 'vendor\wkhtmltopdf\bin\wkhtmltopdf.exe',
'margin' => [
'top' => 45,
'left' => 50,
'bottom' => 15,
'right' => 30
],
'download' => true
]);
// config/routes.php
Router::extensions(['pdf']); // This is above the Router::scope()
// controller/AppController.php
public function initialize()
{
parent::initialize();
$this->loadComponent('Flash');
$this->loadComponent('RequestHandler');
... //more code
}
// action for pdf
public function view($id = null)
{
... //more code
$this->viewBuilder()->options([
'pdfConfig' => [
'title' => 'Supported Cameras',
'filename' => 'SupportedCamerasList'
]
]);
.. //more code
}
}
I'm getting this error when I use this url (localhost/cameras/view/1.pdf):
( ! ) Fatal error: [Cake\View\Exception\MissingTemplateException] Template file "Error\pdf\error500.ctp" is missing.
0 C:\wamp\www\camerasapp\vendor\cakephp\cakephp\src\View\View.php(584): Cake\View\View->_getViewFileName('error500')
1 C:\wamp\www\camerasapp\vendor\friendsofcake\cakepdf\src\View\PdfView.php(103): Cake\View\View->render('error500', 'error')
2 C:\wamp\www\camerasapp\vendor\cakephp\cakephp\src\Error\ExceptionRenderer.php(356): CakePdf\View\PdfView->render('error500', 'error')
3 C:\wamp\www\camerasapp\vendor\cakephp\cakephp\src\Error\ExceptionRenderer.php(325): Cake\Error\ExceptionRenderer->_outputMessageSafe('error500')
4 C:\wamp\www\camerasapp\vendor\cakephp\cakephp\src\Error\ExceptionRenderer.php(327): Cake\Error\ExceptionRenderer->_outputMessage('error500')
5 C:\wamp\www\camerasapp\vendor\cakephp\cakephp\src\Error\ExceptionRenderer.php(192): Cake\Error\ExceptionRenderer->_outputMessage('fatalError')
6 C:\wamp\www\camerasapp\vendor\cakephp\cakephp\src\Error\ErrorHandler.php(144): Cake\Error\ExceptionRenderer->render()
7 C:\w in C:\wamp\www\camerasapp\vendor\cakephp\cakephp\src\Error\ErrorHandler.php on line 156