Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use footers and headers with wkhtmltopdf?

Tags:

wkhtmltopdf

I encountered a situation where I had to use footers and headers in my generated PDF printounts. CSS solution works for the first page only. And the only information I found is that it is not supported in WKPDF at all, but this dates back to 2009, so something might have changed.

Has anyone succeeded in doing it?

Thank you.

like image 399
Vladimir Hraban Avatar asked Oct 09 '12 19:10

Vladimir Hraban


People also ask

How do I create a header and footer in Wkhtmltopdf?

Wkhtmltopdf does support even very complex headers and footers. That command uses the page at www.google.com as a 50mm header for www.stackoverflow.com for every page. Note: If you use a custom page for the header/footer, you need to add <! DOCTYPE HTML> in the beginning of your header/footer HTML!

How do I add a page break in Wkhtmltopdf?

In order to force a page break or new page in a PDF for wkhtmltopdf or Headless Chrome, you need to use the page-break rules. The easiest way is to setup a <div> tag and then apply the style directly to the <div> that wraps the content you want to appear on individual pages.


1 Answers

Wkhtmltopdf does support even very complex headers and footers.

wkhtmltopdf.exe -T 50mm --header-html www.google.com www.stackoverflow.com test.pdf && test.pdf 

That command uses the page at www.google.com as a 50mm header for www.stackoverflow.com for every page.

Note: If you use a custom page for the header/footer, you need to add <!DOCTYPE HTML> in the beginning of your header/footer HTML!

like image 75
Joel Peltonen Avatar answered Sep 20 '22 15:09

Joel Peltonen