php 图像未使用 dompdf 在 PDF 文件中显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16871490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Image is not shown in PDF file using dompdf
提问by Rakesh Shetty
I am using DOMPDF to convert the html into PDF and after converting I'm sending that PDF file to user mail id.
我正在使用 DOMPDF 将 html 转换为 PDF,转换后我将该 PDF 文件发送到用户邮件 ID。
Everything is working perfectly but in PDF file I am not able to see the image of logo of my site. I also searched in stackoverflow for previous question such as :- error in pdf image using dompdf, dompdf and img tag, image wont show
一切正常,但在 PDF 文件中,我看不到我网站的徽标图像。我还在 stackoverflow 中搜索了之前的问题,例如:-使用 dompdf、 dompdf 和 img 标签在 pdf 图像中出错,图像不会显示
I also set DOMPDF_ENABLE_REMOTE
to TRUE
and DOMPDF_PDF_BACKEND
to CPDF
我还设置DOMPDF_ENABLE_REMOTE
要TRUE
与DOMPDF_PDF_BACKEND
以CPDF
my image tag is :-
我的图片标签是:-
<img src="http://www.example.com/clients/myprojects/images/logo.png" alt="" /></a>
<img src="http://www.example.com/clients/myprojects/images/logo.png" alt="" /></a>
I'm giving full path of my website but still it does not show image in my PDF file.
我提供了我网站的完整路径,但它仍然没有在我的 PDF 文件中显示图像。
Thanks in advance.
提前致谢。
回答by Rameshkrishnan S
use full directory path with .jpg image
使用带有 .jpg 图像的完整目录路径
回答by manish1706
It works for me.
这个对我有用。
<img src="<?php echo $_SERVER["DOCUMENT_ROOT"].'/placeholder.jpg';?>"/>
<img src="<?php echo $_SERVER["DOCUMENT_ROOT"].'\placeholder.jpg';?>"/>
<img src="<?php echo $_SERVER["DOCUMENT_ROOT"].'./placeholder.jpg';?>"/>
回答by Shannu Sha
Don't put full path of URL, just put foldername/filename.jpg
不要放网址的完整路径,只要放 foldername/filename.jpg
Example:
例子:
<img src="uploads/kuruvi.jpg">
回答by Waqar Hussain
DOMPDF
DOMPDF
working now with png,jpg
.
现在与png,jpg
.
here what I used.
这里是我用的。
I have index.php
file in route folder and image in subfolder namely images.
我index.php
在路由文件夹中有文件,在子文件夹中有图像,即图像。
$image ="images/".$_FILES['image_index_name']['name'];
$htm= '';
回答by Naved Khan
I my case i spend 2 hour finally i got answer img src not working with url or path you should covert it base64 format
我的情况我花了 2 个小时终于我得到了答案 img src not working with url or path 你应该将它转换为 base64 格式
<?php
$data = file_get_contents('https://teafloor.com/wp-content/themes/teafloor2-0/assets/images/logo.png');
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
?>
<?php echo '<div class="company-logo">
<img src="'.$base64.'" alt="base" />
</div>';
?>
or
或者
<img src="<?php echo $base64; ?>" alt="base" />
回答by Martin Rafael Pérez Lara
I did this:
我这样做了:
$imgurl = $graficas[$i];
$path_parts = pathinfo($imgurl);
$graficas[$i] = $path_parts['filename'].".jpg";
And works. I hope this would help you too
和作品。我希望这也能帮助你
回答by Developer
//use full directory path something like this
$currentsite = getcwd();
$html = <<<HTML
<html>
<img src="{$currentsite}/sites/all/modules/certificate_handler/image002.png" alt="" /></a>
</html>
HTML;
回答by Zae Vega
Remove the alt
attribute and changing it from a self-closing tag (/>
) to a normal one (>
). It worked for me.
删除该alt
属性并将其从自闭合标记 ( />
) 更改为普通标记( >
)。它对我有用。
Note: dompdf seems to have a bad response to any inline styles on img
tags, so I suggest removing them if you′re using any.
注意:dompdf 似乎对img
标签上的任何内联样式都有不良反应,因此如果您正在使用任何样式,我建议将其删除。
回答by Ochi
if I recall it correctly you can put there a full system path to that image - absolute or relative to your script
如果我没记错的话,您可以在那里放置该图像的完整系统路径 - 绝对或相对于您的脚本
回答by JOSE NARVAEZ
You just have to change the line def("DOMPDF_ENABLE_REMOTE", FALSE);
to true
in the file DOMPDF_CONFIG.INC
你只需要行更改def("DOMPDF_ENABLE_REMOTE", FALSE);
到true
文件中DOMPDF_CONFIG.INC