twitter-bootstrap dompdf:找不到图像或类型未知
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40398779/
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
dompdf : image not found or type unknown
提问by H. Patel
Here is my code, I mostly tried all the methods for displaying image on PDF but still didnt work. Could you please help me for this. I also set DOMPDF_ENABLE_REMOTE to true and still results is same.
这是我的代码,我主要尝试了所有在 PDF 上显示图像的方法,但仍然没有奏效。你能帮我解决这个问题吗?我还将 DOMPDF_ENABLE_REMOTE 设置为 true 并且结果仍然相同。
require_once("dompdf/autoload.inc.php");
//require('WriteHTML.php');
$html = '<body>
<div id="watermark"><img src="/var/htdocs/PDF/header.png" height="100%" width="100%"></div>
<div id="header">
<h3 style="padding-top:10px;">'.$_POST['name'].'</h3>
</div>
<div id="footer">
<h3 style="padding-top:8px; padding-right:25px;" class="CIJ">ABSOLUTE MARKET INSIGHTS</h3>
</div>
<div>
<br><br><div class="ooo" style="padding-top: 20px;">'.$_POST['comment'].'</div>
</div>
</body>';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$canvas = $dompdf->get_canvas();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream($_POST["name"], array("Attachment" => false));
回答by Iskar
You should be using the full URL instead of a direct path. Especially when it is not a static image: dompdf will open that php script directly, so it won't be executed as if it's a PHP script.
您应该使用完整的 URL 而不是直接路径。特别是当它不是静态图像时:dompdf 会直接打开那个 php 脚本,所以它不会像一个 PHP 脚本一样被执行。
If the full URL doesn't work, you can also show what the result of header.php is. Some good things to keep in mind are to send proper content-type headers and so on.
如果完整的 URL 不起作用,您还可以显示 header.php 的结果是什么。要记住的一些好处是发送正确的内容类型标头等。
回答by FamousWolluf
Have you tried full path/url:<img src="http://domain.com/var/htdocs/PDF/header.png" height="100%" width="100%">
您是否尝试过完整路径/网址:<img src="http://domain.com/var/htdocs/PDF/header.png" height="100%" width="100%">
Or with a more variable solution:
或者使用更可变的解决方案:
$baseurl = "http://www.domain.com";
echo '<img src="' . $baseurl . '/var/htdocs/PDF/header.php" height="100%" width="100%">';

