Closed eved42 closed 4 years ago
Where does the "path" variable comes from in your header.html.twig?
@dsentker From the controller :
$path = $request->server->get('DOCUMENT_ROOT'); // C:/wamp64/www/
$path = rtrim($path, "/"); // C:/wamp64/www
$header = $this->renderView('contracts/pdf/header.html.twig', array(
'path' => $path
));
Thank you!
@eved42 Sorry, but this solution not working!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
It's not an issue but an example of a correct way to generate a PDF file from a Twig view in a Symfony3 project, with a header and a footer.
I think it's important to show a complete configuration because I spent lots of hours to make it works, I think it can be very useful for everyone who starts with KnpSnappyBundle.
My project : Symfony 3.3.* in local with Wampserver 3.0.0
1) Install KnpSnappyBundle 2) Install wemersonjanuario/wkhtmltopdf-windows
3) config.yml
4) header.html.twig You have to add a complete path to your assets.
5) content.html.twig
6) footer.html.twig (example of using a page counter)
7) Controller :
Your 3 Twig files must be "stand-alone" HTML files with a DOCTYPE,
<html>
,<head>
and<body>
tags. If you have some errors, they probably came from a bad link to a css file, picture, etc.Hope it helps ! ;-)