FriendsOfCake/CakePdf

Render "normal" template

LDSign opened this issue · 6 comments

Hi

Is it possible to render a "normal" template withourt using the one in the pdf subDir?

I would like to make a "Save as pdf"-Button on every normal page which will call the same link with pdf-extension.

I don't want to duplicate all my template fiels for this.

Setting the subDir to null in PdfView.php will to the job, but thats just for testing. How can I set the subDir "from outside"? Or is there an other way? Any hints?

Thanks,
Frank

ADmad commented

You'll have to extend PdfView and modify the $subDir and $layoutPath properties.

That said unless your web views use relative simple HTML structure you will be in a world of pain if you allow every page to be converted to PDF.

Ok, thanks :)

Yes sure - the plan is to restrict the conversion to some specific pages which custom layout.

Just one question in addition:

Is it possible to bind
"$this->viewBuilder()->setClassName('CakePdf.Pdf');"
to the pdf-extension?

ADmad commented

Just check the URL extension using $this->request and set the classname conditionally.

Ok, thanks again :)

Can you just give me a last hint please? :)

Ive have successfully extended the base class and using it works. But the parent class ignores the "subDir overwrite". I have no idea why? :(

namespace App\View;

use CakePdf\View\PdfView as CakePdfView;
use CakePdf\Pdf\CakePdf;
use Cake\Core\Configure;
use Cake\Core\Exception\Exception;
use Cake\Event\EventManager;
use Cake\Http\Response;
use Cake\Http\ServerRequest;
use Cake\View\View;

class PdfView extends CakePdfView
{
    public function __construct(ServerRequest $request = null, Response $response = null, EventManager $eventManager = null, array $viewOptions = []) {
        $this->subDir = null;
        parent::__construct($request, $response, $eventManager, $viewOptions);
    }
}
ADmad commented

This is not a help forum. Please visit one of the following CakePHP support forums for help:

Thanks!