0

I'm using the mPDF libary to turn HTML pages into PDFs.

This library works great on my local machine and development servers running PHP 5.6.

However on a newly provisioned Ubuntu 16 box from Amazon, with Apache 2.4.18 and PHP 7 I can't get it working.

The symptom is that the PDF is never generated - the browser just keeps spinning for ever, and eventually I have to quit the browser to escape from the process. I do not receive any error messages.

I've worked through my script to see where the process gets stuck, and it's on this method:

$mPDF->WriteHtml($html);

I have tried passing a very simple HTML string into the function, for example:

<html>
    <head>
        <meta charset="utf-8">
    </head>
    <body>
    <b>Hello!</b>
    </body>
</html>

And that does work.

So I wondered about the quality of my HTML. Running my HTML through the W3 Validator revealed a couple of errors which I've now fixed, but this has not resolved my issue.

So I'm now wondering about the size of my HTML - it's a large page that's being rendered, often in excess of 20 pages on the PDF.

My script allocates plenty of memory for the process:

ini_set('memory_limit', '1024M');

And the server has 8G of memory in total.

Is there anything I should check in the server config which might be affecting mPDF?

Thanks in anticipation.

Edit

After further debugging and stripping the HTML back to smaller and smaller pieces I have been able to get the PDF to generate - but it's extremely slow.

mPDF also seems to fail to find the image assets, so I get broken image symbols on the PDF. I wonder if this server setup has a strange webroot / basePath that means mPDF can't find the assets it's looking for?

Edit 2

Wondering if this issue is now a duplicate of mPDF not rendering images (mPDF error: IMAGE Error Could not find image file)

I'm seeing the same issues of slow load and missing images

Community
  • 1
  • 1
JamesG
  • 1,687
  • 2
  • 25
  • 39
  • Add `error_log=error_log` to your php.ini, run the script and check for the file `error_log`. Or, better yet, follow the advices on http://stackoverflow.com/a/21086666/2729937 (including the comment, adjusting the paths to your setup) – Ismael Miguel Jun 30 '16 at 17:21

1 Answers1

0

So the server had an IP firewall and mPDF uses file_get_contents() to reference assets for the PDF as external assets, including the domain name:

file_get_contents('http://server.com/asset/anAsset.jpg');

This means the request was going out of the server, coming back to it and being refused by the firewall.

Removing the firewall solved our issue.

I'd still love to know if mpdf can reference assets locally. The docs for its basePath property seem to indicate that it always used a full domain URL:

https://mpdf.github.io/reference/mpdf-functions/setbasepath.html

JamesG
  • 1,687
  • 2
  • 25
  • 39