WkHTMLtoPDF不加载本地CSS和图像 [英] WkHTMLtoPDF not loading local CSS and images
问题描述
我看到过很多与这个问题非常相似的问题,所以我一开始就很犹豫。但没有任何建议解决了我的问题,我似乎无法弄清楚自己有什么问题。
对于我为一个客户制作的项目,他们希望能够将报价转换为他们的客户(使用在线表单生成)到PDF。够简单。由于整个项目都在PHP中,我使用了以下简单的过程:
$ b
- 将报价保存为临时HTML文件
- 使用WkHTMLtoPDF将HTML文件转换为PDF
- 输出此PDF文件
- 清理(删除临时文件) / li>
- 清理(删除临时文件) / li>
直到他们更换服务器为止。新服务器有一个防火墙。
起初PDF转换步骤是返回一个防火墙页面,表示服务器无法建立出站连接。为了解决这个问题,我直接提供了HTML文件,而不是链接到它(/var/www/mysite/temp/18382.html而不是www.example.com/temp/18382.html)。这转换了HTML,但防火墙阻止了CSS和图片的加载。
我可以通过直接将它嵌入到站点而不是链接到它来使用CSS < style>
标记),但这对图像无效
我首先尝试使用相对链接。我将< img src =http://www.example.com/temp/image.jpg/>
更改为< img src =./ image.jpg/>
。这是行不通的。
接下来我尝试了< img src =file:/// var / www / mysite / temp / image .jpg/>
但这不起作用,要么
我仔细阅读并查看了WkHTMLtoPDF手册,并尝试了几种不同的方法命令行参数,如 - enable-local-file-access
, - 启用/ var / www / mysite / temp /
和 - images
但是没有任何东西可以修复它
如果你在Linux上检查你的图像的所有权。对于Windows,您可以在 http://code.google.com/p/wkhtmltopdf/wiki/Usage 。
我尝试了不同类型的图片路径:
-
< img src =file:///var/www/testpdf/flowers.jpg>< br>
-
< img src =./ flowers.jpg>< br>
-
< img src =flowers.jpg>< br>
-
< img src =/ var / www / testpdf / flowers .jpg>< br>
所有图片都显示正确。我没有使用任何命令行参数
(仅 wkhtmltopdf /var/www/testpdf/makepdf.html makepdf.pdf
)
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
If your are on linux check the ownership of your images. For windows you will find some info on http://code.google.com/p/wkhtmltopdf/wiki/Usage.
I tried different kind of paths to the image:
<img src="file:///var/www/testpdf/flowers.jpg"><br>
<img src="./flowers.jpg"><br>
<img src="flowers.jpg"><br>
<img src="/var/www/testpdf/flowers.jpg"><br>
all images are showed correct. I didn't use any command line arguments
(only wkhtmltopdf /var/www/testpdf/makepdf.html makepdf.pdf
)
这篇关于WkHTMLtoPDF不加载本地CSS和图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!