Reputation: 843
I am wondering if it is possible to render an action's view without loading in the browser?
I'm using a cakephp component that used mPDF to generate PDF files. The component works well if you load the action and view in a browser but when I want to generate and save the pdf to the drive it doesn't seem to kick in, I'm assuming it's because the view isn't loaded property.
The component I am using is: https://github.com/segy/Mpdf
So basically I have a function called mail_merge which generates a pdf using the mentioned component, I need to call the mail_merge function from another function within the same controller to generate the pdf but without loading in the browser.
Thanks
UPDATE:
I worked out how to set the view as a variable and then write it to the pdf in the function.
ADDED THIS:
// RENDER THE VIEW AND SET AS A VARIABLE TO WRITE THE HTML
// --------------------------------------------------------------------------->
$response = $this->render('mail_merge');
$thebody = $response->body();
$this->Mpdf->WriteHTML($thebody);
Unfortunately my PDF still won't generate so I guess the issue is something else.
Upvotes: 0
Views: 1005
Reputation: 2545
Try this way:
$response = $this->render('mail_merge');
$thebody = $response->body();
$this->Mpdf->WriteHTML($thebody);
$this->Mpdf->Output('filename.pdf');
Upvotes: 1