I'm trying to build invoice pdf with wkhtmltopdf library and a symfony2 wrapper KnpSnappyBundle.
I want to add a footer on every page with the wkhtmltopdf option footer-html. In command-line, everything works fine, my pdf is built and a footer is repeated on every page. But when I use the bundle service :
$snappy = $this->get('knp_snappy.pdf');
$snappy->setOption('footer-html', 'http://www.google.com');
$content = $snappy->getOutputFromHtml($html);
return new Response(
$content,
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
it returns an error :
The exit status code '1' says something went wrong:
stderr: "Loading pages (1/6)
[> ] 0%
[======> ] 10%
Error: Failed loading page http://www.google.com (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: HostNotFoundError
"
stdout: ""
command: C:\wkhtmltopdf\bin\wkhtmltopdf.exe --lowquality --dpi "300" --margin-bottom "0" --margin-left "0" --margin-right "0" --margin-top "0" --page-size "A4" --background --encoding "utf-8" --footer-html "http://www.google.com" "http://www.google.com" "test.pdf".
Did any already succeed in using footer-html option with KnpSnappyBundle ?
setOption('footer-html', 'google.com');
and report back please - wkhtmltopdf falls back tohttp://
protocol by default. – Nicolai Fröhlich