简体   繁体   English

图像未在 dompdf 中呈现

[英]Image not rendering in dompdf

I am using codeIgniter and dompdf for my application for generating pdfs.我在我的应用程序中使用 codeIgniter 和 dompdf 来生成 pdf。 The below code is the code which i am using to display an image.下面的代码是我用来显示图像的代码。

<div class=\"block_head\">
     <h2>Image display</h2>";
     $image_location = "/images/xxx.png";
     $html .="<img src=\"".$image_location."\" width=\"200\" height=\"200\" />
</div>";

I tested and debugged all ways whether i am doing something wrong.无论我做错了什么,我都进行了各种测试和调试。 Like this first i checked whether the path is wrong.像这样首先我检查了路径是否错误。 This is path on the server.这是服务器上的路径。 It's correct.这是正确的。 I tested by echoing $html also it's showing perfectly path.我通过回显 $html 进行了测试,它也显示了完美的路径。 When i clicked on that path image is displaying.当我单击该路径图像时显示。 But when i am trying to render it in pdf it's not displaying.但是当我尝试以 pdf 格式呈现它时,它没有显示。

Note: PDF is generating perfectly without image.注意:PDF 在没有图像的情况下完美生成。

Try as below尝试如下

if you are providing full URI to the image it is treated as external, so defined costant DOMPDF_ENABLE_REMOTE must be set to true.如果您为图像提供完整的 URI,则它被视为外部图像,因此必须将定义的 costant DOMPDF_ENABLE_REMOTE 设置为 true。

Are you loading this document into dompdf using $dompdf->load_html($html);您是否使用$dompdf->load_html($html);将此文档加载到$dompdf->load_html($html); ? ? If so then you're probably running into a context problem.如果是这样,那么您可能会遇到上下文问题。 When you load a document in this manner dompdf has no knowledge of the document base path.当您以这种方式加载文档时,dompdf 不知道文档基本路径。 Because of this it assumes you are working from the local file system.因此,它假定您正在从本地文件系统工作。 In this context the root path "/" translates to the root of the local file system not the root of the web content directory.在这种情况下,根路径“/”转换为本地文件系统的根,而不是 Web 内容目录的根。 Either use a path relative to the PHP file implementing dompdf, or specify the full path in the current files system.要么使用相对于实现 dompdf 的 PHP 文件的路径,要么指定当前文件系统中的完整路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM