dompdf不显示由PHP文件生成的图像 [英] dompdf not displaying image generated by PHP file

查看:638
本文介绍了dompdf不显示由PHP文件生成的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用dompdf来生成PDF文件。在文件中,我包括一个由PHP通过使用生成的图像;

I'm using dompdf to generate a PDF file. In the file I'm including an image that is generated on the fly by PHP by using;

< img src =image.php />

当我查看页面时,我可以看到一个错误,找不到图像,链接到假定未找到的图像

When I view the page I can see an error saying "Image not found" which links to the supposedly not found image which displays fine when you click on it.

我试过在生成图片的页面中添加.png扩展名,但没有任何区别。我还将生成的图像保存到服务器,并链接到它,它工作正常。

I've tried adding a .png extension to the page generating the image but that doesn't make any difference. I've also saved the generated image to the server and linked to that instead and it works fine.

我可以想到解决这个唯一的方法是保存图像在服务器上,然后链接到那。理想情况下,我不想这样做,所以我想知道有没有人曾经碰到过这个问题,或者任何人都可以想到一个解决方案。

The only method I can think of to solve this is to save the image on the server and then link to that. Ideally, I don't want to do this so I was wondering if anybody had come across this before or if anyone can think of a fix for it.

版本dompdf我使用的是0.6.0 beta 3,我使用它与CodeIgniter。

The version of dompdf I'm using is 0.6.0 beta 3 and I'm using it with CodeIgniter.

推荐答案

HTML文档转换成dompdf? $ dompdf-> load_html() $ dompdf-> load_html_file()?要访问PHP生成的图像,您应该使用后者。此外,除非您通过Web服务器加载文档dompdf将抓取文件本身,而不是渲染的文件。由于image.php不是有效的图像类型,dompdf将无法加载它。

How are you loading your HTML document into dompdf? $dompdf->load_html()? $dompdf->load_html_file()? To access a PHP-generated image you should be using the latter. Additionally, unless you are loading the document through a web server dompdf will grab the file itself, not the rendered file. Since image.php is not a valid image type dompdf will fail to load it.

有两种解决方案:


  1. 通过Web服务器加载文档,例如 $ dompdf-> load_html_file('http://example.com/mydoc.html'); 。当您执行此操作时,图片引用将被解释为 http://example.com/image.php

  2. 参考您的图片使用完整的URL(包括域),以便您的服务器在将其发送回dompdf之前对其进行处理,例如< img src =http://example.com/image.php/>

  1. Load your document through your web server, e.g. $dompdf->load_html_file('http://example.com/mydoc.html');. When you do this the image reference will be interpreted as http://example.com/image.php.
  2. Reference your image using a full URL (including domain) so that your server processes it before sending it back to dompdf, e.g. <img src="http://example.com/image.php" />.

这篇关于dompdf不显示由PHP文件生成的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆