I’m using PHP 7.3 on my dev machine. I’ve installed the latest version of MPDF with composer. I’ve an action in my MVC framework (Phalcon 3.4) where I create an object of Mpdf. On the dev machine it works. I get my PDF on screen. This is my action code.
public function printAction()
{
$this->view->disable();
....
//var_dump(class_exists('MpdfMpdf', true)); --> output: true
//exit;
$mpdf = new MpdfMpdf(['debug' => true]);
$html = '...';
$mpdf->WriteHTML($html);
$mpdf->Output();
}
I uploaded the code on the server and did ‘composer update’. When I run the code, I get an HTTP 404 response. I put a ‘exit’ statement before the object creation of mPDF and the HTTP 404 is gone.
$mpdf = new MpdfMpdf(['debug' => true]);
this line seems to be the problem. Nothing is written in the apache2 error log nor in the access log. Other requests in the controller are executed perfectly.
The server uses PHP 7.0. All the extensions are loaded.
I checked if the class Mpdf exists with class_exists. It outputs ‘true’.
What did I oversee?
2
Answers
In the library mPDF, an exception is throw but wasn't catched. Instead of HTTP 500, it resulted in a 404 error.
The library hadn't write permission on the temp folder.
For those happening upon this topic, my issue was the reference to this stylesheet (worked fine from my local machine, but not when called from the server):
This resulted in the following output:
string(15) "HTTP error: 404"
There were no errors in the logs (though technically it’s a text string, not an actual HTTP 404 that was sent to the browser).
Obviously I have some code that calls the creation of the PDF in a specific way, but in any case: check what you’re doing, and turn off things until it no long breaks.