Closed kojuka closed 6 years ago
Thanks, I totally agree. To do that, I can think of three possible options:
Modify the PDF with a separate library after Chrome has rendered.
Check if Puppeteer/Chrome print protocol would allow injecting headers and footers in a more custom way. I doubt this is supported, but haven't checked.
Out of these options, I'd recommend to investigate the first one. I'm not so excited about the second option.
@webular assuming you control how the HTML for those pages is generated, why don't you add the header/footer to the HTML using something like a template language (e.g. Jinja, Twig,..), a bit how you would handle email templates.
@fabiosussetto I do control the html. But I find it nontrivial - at the least I don't have much experience with this. I'm open to direction -- All I really need is to add a logo and project name, and page number at the top of every generated PDF. I'd also need to add a one line footer to each page. Got any examples you can point me to on doing this with email templates like you suggest?
I'm really pleased to see the traction this project has received and would love to make the switch.
With Puppeteer 1.0.0 it is now possible to add a custom header/footer (source). This repo currently uses ^0.11.0, so after an update it might work :).
Made a PR #56 to upgrade to v1.0.0, which would fix this issue 😃.
The support for this is now in master, and also released to the demo Heroku app. However there are some caveats with Chrome's footer and header support. See https://github.com/alvarcarto/url-to-pdf-api/issues/77
I found puppeteer is a good tool for converting from html to pdf. But the footerTemplate must be the same on all pages? Now I need, for example, pages' footer like this:
(page 1) pageNumber of totalNumber---------------------------vocabulary list
(page 2) vocabulary list-------------------------------------pageNumber of totalNumber
(page 3) pageNumber of totalNumber---------------------------vocabulary list
I prepare 2 Templates for odd and even num pages What should i do?
Great work here -- its 2017 and generating PDFs is still unnecessarily complicated. I'm currently using wfhtmltopdf. I'd love to stop using it, and use this project as a micro service to handle all my pdf needs. However the one thing I can't figure out how to do is add a footer and/or header to every generated page. Header/footer would need to have stuff like logo, page number, warning, date, invoice number etc, so it needs to be more custom than the standard
pdf.displayHeaderFooter
option allows.Does anyone have any experience with this? Is there something I'm missing? Thanks again for this awesome project.