Problem saving pdf with wkhmltopdf - Cakephp 3

Viewed 38

I'm using CakePdf

The documentation gives this example to create inside a folder:

<?php
    $CakePdf = new \CakePdf\Pdf\CakePdf();
    $CakePdf->template('newsletter', 'default');
    $CakePdf->viewVars($this->viewVars);
    $CakePdf->write(APP . 'files' . DS . 'newsletter.pdf');

I replaced by:

$CakePdf->write("/webroot/img/" . 'newsletter.pdf');

However, the file is not created. I am grateful if someone can analyze me or indicate a way to implement this!

1 Answers

Always use DIRECTORY_SEPARATOR or DS in CakePHP applications.

But in this case you need to use the predefined constan WWW_ROOT to build the correct path in the backend of the application.

$CakePdf->write(WWW_ROOT . 'img' . DS . 'newsletter.pdf');

In templates create link to file like

<a href="/img/newsletter.pdf">News Leter</a>
Related