55

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.

Joshua Pinter
  • 37,288
  • 19
  • 208
  • 218
Vladimir Hraban
  • 3,123
  • 3
  • 21
  • 41

1 Answers1

94

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!

Joel Peltonen
  • 11,167
  • 4
  • 60
  • 93
  • Yeah, the documentation lags behind the new version. I use http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf_0.10.0_rc2-doc.html which is older but works well enough. Then there is `--extended-help` as well, I have copied that output to a text file. – Joel Peltonen Oct 12 '12 at 06:55
  • @Nenotlep, the link you gave to the madalgo.au.dk site does not work. – marienke Oct 21 '13 at 09:51
  • @marienke Do you get a 404? For me it looks like it's working fine. – Joel Peltonen Oct 21 '13 at 11:45
  • Google Chrome tells me that "the web page is not available" – marienke Oct 22 '13 at 07:01
  • @marienke Are you sure you are not being firewalled or something? http://i.imgur.com/wLpqqVC.png keeps working for me at work and at home. – Joel Peltonen Oct 22 '13 at 10:06
  • @Nenotlep, how to add custom header to pdf page? i am able to add link to header but I want my own header. Please help – Sushant Jun 11 '14 at 07:35
  • @Sushant Write a custom header HTML page and save it as "myheader.html". Then simply use a command like this `wkhtmltopdf --header-html myheader.html www.mlparena.com output.pdf`. – Joel Peltonen Jun 11 '14 at 07:56
  • 1
    @Nenotlep, thanks for reply. I tried this way, but it shows blank white space at header place – Sushant Jun 11 '14 at 08:43
  • 13
    @Nenotlep, its done. was missing in header.html :) thanks a lot! – Sushant Jun 11 '14 at 08:58
  • @Sushant wow, thank you - you just saved my day! can't believe that they did not mention that ` ` at the top of your headers/footers is needed in the wkhtmltopdf documentation! – low_rents Mar 31 '16 at 10:00
  • 1
    @VishalZanzrukia please post this problem as a separate question, such as "Wkhtmltopdf header is not working with cover option" where you describe the problem you are having. You can link the question here and I'll try to figure it out with you if you want! – Joel Peltonen Oct 09 '18 at 07:23
  • @Nenotlep Thanks for your support, but I could manage it somehow as of now, it will create problem again, I am surely create new question and also will ask you for help :) – Vishal Zanzrukia Oct 09 '18 at 15:10