Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do page numbering in header/footer htmls with wkhtmltopdf?

I'm developing an electronic invoicing system, and one of our features is generating PDFs of the invoices, and mailing them. We have multiple templates for invoices, and will create more later, so we decided to use HTML templates, generate HTML document, and then convert it to PDF. But we're facing a problem with wkhtmltopdf, that as far as I know (I've been Googleing for days to find the solution) we cannot simply both use HTML as header/footer, and show page numbers in them.

In a bug report (or such) ( http://code.google.com/p/wkhtmltopdf/issues/detail?id=140 ) I read that with JavaScript it is achievable this combo. But no other information on how to do it can be found on this page, or elsewhere.

It is, of course not so important to force using JavaScript, if with wkhtmltopdf some CSS magic could work, it would be just as awesome, as any other hackish solutions.

Thanks!

like image 683
Tamás Barta Avatar asked Aug 24 '11 11:08

Tamás Barta


People also ask

How do I add page numbers to a footer in HTML?

Refer to Adding Content to a Header or Footer for an example of how to create content for a header or footer. 2. Highlight numbered-header then the Edit button to open the Generated Text Editor. Place your cursor in the right hand cell of the header table, then choose Insert > Page Number.

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 align page numbers in footer?

To change the numbering alignment, go to Header & Footer > Page Number > Page Number. Choose the alignment you want and select OK. Go to Header & Footer > Close Header and Footer or double-click outside the header to exit.


1 Answers

Actually it's much simpler than with the code snippet. You can add the following argument on the command line: --footer-center [page]/[topage].

Like richard mentioned, further variables are in the Footers and Headers section of the documentation.

like image 69
makro Avatar answered Sep 16 '22 13:09

makro