I am getting the error
"Image not found or type unknown"
after downloading PDF in Symfony 4 using dompdf package.
My method in my controller class:
public function dompdf(EvaluationRepository $evaluationRepository)
{
// Configure Dompdf according to your needs
$pdfOptions = new Options();
$pdfOptions->set('IsFontSubsettingEnabled', true);
$pdfOptions->set('IsHtml5ParserEnabled', true);
$pdfOptions->set('isRemoteEnabled', true);
$pdfOptions->set('defaultFont', 'Arial');
// Instantiate Dompdf with our options
$dompdf = new Dompdf($pdfOptions);
// Retrieve the HTML generated in our twig file
$html = $this->renderView('analyse/approbation/mypdf.html.twig', [
'evaluations' => $evaluationRepository->findAll(),
]);
$dompdf->loadHtml($html);
$dompdf->render();
$dompdf->stream("mypdf.pdf", [
"Attachment" => false
]);
}
My HTML twig-template
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
}
</style>
</head>
<caption>
<img src="{{ pathToPublic }}/images/cpmpss.jpg" align="middle" style="width:100%">
</caption>
Note: pathToPublic variable globale in twig.yaml contain the absolute pathe
pathToPublic: '%kernel.project_dir%/public'
Please suggest how can I fix it.