Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dompdf : image not found or type unknown

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));
like image 917
H. Patel Avatar asked Nov 03 '16 10:11

H. Patel


3 Answers

You need to add 'isRemoteEnabled' => true

return PDF::setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true])->loadView('reports.invoiceSell')->stream();
like image 112
Bauroziq Avatar answered Nov 17 '22 14:11

Bauroziq


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.

like image 33
Iskar Avatar answered Nov 17 '22 15:11

Iskar


Finally I Got Correct Solution to work with any server -> Use Base64 in Img src attribute :)

like image 6
Mostafa Mahmoud Avatar answered Nov 17 '22 13:11

Mostafa Mahmoud