dompdf : image not found or type unknown

北城以北 提交于 2019-12-11 04:16:25

问题


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.

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));

回答1:


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.

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.




回答2:


Have you tried full path/url:
<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%">';


来源:https://stackoverflow.com/questions/40398779/dompdf-image-not-found-or-type-unknown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!