When i try to load a HTML file which is in my storage Directory of my Laravel Project. I specified the path correctly and the file is there.
I tried moving the html file to the root of dompdf in the vendor map but that didn't help.
Changing the path of chroot messes with other parts of dompdf itself. giving an error about not being able to find fonts.
This is the error i get
`Permission denied on <!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div class="body">
<h2>test</h2>
<hr/>
<p class="content">content test</p>
</div>
</body>
</html>. The file could not be found under the directory specified by Options::chroot.`
Are there any changes I could make in dompdf.php or Options.php to make it work?
dompdf limits loading files from the local file system to the path set in the chroot option (by default the dompdf install directory, ref).
However, that's not what's causing your problem. You appear to be loading the HTML source instead of specifying the path to the HTML. Thus the reason you are seeing the HTML source in the permission denied error instead of a file path.
How are you using dompdf? You should probably be calling $pdf->loadHtml() rather than how you are currently doing it.
Currently the code setup is as following;
$html = file_get_contents(__DIR__ . '/../../../vendor/dompdf/pdf_mail.html');
$dompdf = new Dompdf();
$dompdf->setBasePath('/../');
$dompdf->loadHtmlFile($html);
$dompdf->setPaper('a4', 'portrait');
$dompdf->render();
You should use this:
$html = file_get_contents(__DIR__ . '/../../../vendor/dompdf/pdf_mail.html');
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setBasePath('/../');
$dompdf->setPaper('a4', 'portrait');
$dompdf->render();
Or this:
$dompdf = new Dompdf();
$dompdf->loadHtmlFile(__DIR__ . '/../../../vendor/dompdf/pdf_mail.html');
$dompdf->setBasePath('/../');
$dompdf->setPaper('a4', 'portrait');
$dompdf->render();
Most helpful comment
You should use this:
Or this: