I have been trying for a couple of days now to enable PDFs on my web app. However, I can't make it work.
I have the following configured:
// AppController.php
class AppController extends Controller
{
/**
* Initialization hook method.
*
* Use this method to add common initialization code like loading components.
*
* e.g. `$this->loadComponent('Security');`
*
* @return void
*/
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
// some other code for authentication
}
}
// bootstrap.php (at the end of the file)
Plugin::load('CakePdf', ['bootstrap' => true, 'routes' => true]);
Configure::write('CakePdf', [
'engine' => 'CakePdf.DomPdf',
'margin' => [
'bottom' => 15,
'left' => 50,
'right' => 30,
'top' => 45
],
'download' => true
]);
// routes.php
Router::defaultRouteClass(DashedRoute::class);
// Add PDF Extensions
Router::extensions(['pdf']);
Router::scope('/', function (RouteBuilder $routes) {
// OrdersController.php
public function view($id = null)
{
// some code
$this->viewBuilder()->options([
'pdfConfig' => [
'title' => 'Work Order PDF',
'filename' => 'workorder'
]
]);
// other code
}
I have a created a subfolder 'pdf' in Template\Orders where I have a view.ctp file. I also have a default.ctp and BootstrapUI.default.ctp in Layout\pdf (I also use FriendsOfCake/bootstrap-ui).
I have already tried WkHtmlToPdf (downloaded binaries and installed it) and DomPdf (used composer in PhpStorm to download and implement it), but it does not work.
I get the message "The requested resource /orders/view/28.pdf was not found on this server."
What am I forgetting?