I am getting errors when I tried to include image in dompdf. I am using version 1.2.1
I tried with base4 encoded image as well from one of the solutions mentioned in forums, that also not working.
<?php
namespace Dompdf;
require_once 'dompdf/autoload.inc.php';
$_dompdf_show_warnings = true;
$_dompdf_warnings = [];
$path="http://localhost/dompdf/assets/images/logo.png";
$data = file_get_contents($path);
$image = 'data:image/' . $type . ';base64,' . base64_encode($data);
$htmldata = '<!DOCTYPE html>
<html>
<head>
<title>Results</title>
<style>
body {
background-color: lightblue;
}
.container {
width: 90%;
max-width: 600px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="container">
<h1>test pdf</h1>
<img src="/assets/images/logo.png" alt="image">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer egestas elementum justo, eget maximus odio ultricies eu. Aenean faucibus varius massa, sit amet sagittis neque vulputate luctus.</p>
<img src="'.$image.'" alt="base64">
</div>
</body>
</html>';
$options = new Options();
$options->getChroot($_SERVER['DOCUMENT_ROOT']."/dompdf/");;
$options->setisRemoteEnabled(true);
$options->setIsHtml5ParserEnabled(true);
$dompdf = new Dompdf($options);
$dompdf->loadHtml($htmldata);
$dompdf->render();
$dompdf->stream("",array("Attachment" => false));
exit(0);
?>
Getting these errors, first is when I include the image path and second for base64 encoded one. I tried to enable remote, added chroot path and tried several solutions found on internet. Nothing helped.
Permission denied on /assets/images/logo.png. The file could not be found under the paths specified by Options::chroot. /assets/images/logo.png
Unable to create temporary image in /var/folders/bc/tnbzrzvd1k370wftgbm5lnqh0000gn/T data:image/;base64,iVBORw0KGgoAAAANSUhEUgA
Can anyone suggest a solution for this?