Header and footer in each page
bettinz opened this issue Β· comments
Hello, is it possible to add header and footer to each page and not in the first/last page?
edit: I'm using the integration with symfony π
Thanks π
Hello,
I'm afraid that the only way to do it with this library is to generate different PDFs for the first page, for the middle pages and for the last page and then merge them together using tools like Ghostscript.
Thank you @alexpozzi , what I'm trying to do is to add page number in the footer as explained here:
KnpLabs/KnpSnappyBundle#286
If I've to generate different PDFs I think the page number will be wrong. Am I right?
Thanks
Hello,
Yes this is possible. Create 3 views, one for header, one for footer and one for content.
Each view needs to be a "complete" HTML page with a <!DOCTYPE html>
at the begining of the file, and with <html>
, <head>
and <body>
tags.
Then, you just need to specify the header and footer to Knp Snappy and that's all.
// HTML content
$header = $this->renderView('header.html.twig');
$footer = $this->renderView('footer.html.twig');
$html = $this->renderView('content.html.twig');
// PDF to download
return new PdfResponse(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html, array(
'header-html' => $header,
'footer-html' => $footer
)), 'file.pdf'
);
Hello,
by the way, how can I generate header/footer only for specific pages ?
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.