Laravel dompdf error "Image not found or type unknown"
I've solved it:
1- Call the DomPDF library:
require_once ($_SERVER['DOCUMENT_ROOT'] . "/mi/LiquidacionesSueldo/include/dompdf/autoload.inc.php");
ob_start();
2- Generate the HTML file, I do it with a function that returns a simply HTML table:
get_dias_goce_sueldo($_POST['run'],$_POST['dvr'],$_POST['cantidad_dias'],$_POST['desde'],$_POST['hasta'],$_POST['am_pm']);
3- Now, you must initialize the DomPDF object, note all the options that I set:
$dompdf=new Dompdf\Dompdf();
$dompdf->set_option('isHtml5ParserEnabled', true);
$dompdf->set_option('isRemoteEnabled', true);
$dompdf->loadHtml(ob_get_clean());
$dompdf->set_paper('letter', 'portrait');
$dompdf->render();
$dompdf->stream("Solicitud_de_permiso_con_goce_de_sueldo.pdf", array('Attachment'=>1));
NOTE: in my function, in the HTML table, I call the image with the full path, this way:
<img src="'.$_SERVER['DOCUMENT_ROOT'].'/mi/DiasAdministrativos/logo.png">
That's all, I hope this will be usefull, that was for me.
According to this question you have to use the full server path try:
<img src="{{ public_path("storage/images/".$user->profile_pic) }}" alt="" style="width: 150px; height: 150px;">
Assuming the image is stored in your public directory.
public function pdf()
{
$users = User::get();
$pdf = PDF::loadView('pdf', compact('users'));
$pdf->getDomPDF()->setHttpContext(
stream_context_create([
'ssl' => [
'allow_self_signed'=> TRUE,
'verify_peer' => FALSE,
'verify_peer_name' => FALSE,
]
])
);
return $pdf->download('Users.pdf');
}