I've seen multiple questions that are very similar to this one, so I was hesitant at first to post it. But nothing suggested resolved my issue and I can't seem to figure out what's wrong myself.
For a project I made for one client they wanted to ability to convert quotes for their customers (generated using an online form) to PDFs. Simple enough. As the entire project was in PHP, I used the following simple process:
- Save the quote as a temporary HTML file
- Use WkHTMLtoPDF to convert the HTML file to a PDF
- Output this PDF file
- Clean up (delete temporary files)
This worked until they changed servers. The new server has a firewall.
At first the PDF conversion step was returning a firewall page saying that the server couldn't make outbound connections. To resolve this I fed the HTML file directly instead of linking to it (/var/www/mysite/temp/18382.html instead of www.example.com/temp/18382.html). This converted the HTML, but the firewall prevented the loading of CSS and images
I can overcome the CSS by simply embedding it directly in the site instead of linking to it (using the <style>
tags), but this doesn't work for images
I tried using relative links first. I changed <img src="http://www.example.com/temp/image.jpg" />
to <img src="./image.jpg" />
. This didn't work.
Next I tried <img src="file:///var/www/mysite/temp/image.jpg" />
but this didn't work, either
I read around and look through the WkHTMLtoPDF manual and I tried several different command line arguments like --enable-local-file-access
, --enable /var/www/mysite/temp/
, and --images
but nothing seems to fix it
chown
just before the call to WkHTMLtoPDF and suddenly it's working. Please post this as an answer so I can accept it =) – Incumber