Adding a header, footer, and page numbers to your PDFs with wkhtmltopdf is rather straight forward. We provide a list of advanced options here. Wkhtmltopdf is a popular open source PDF rendering engine. The techniques described below will work for wkhtmltopdf as well as Api2Pdf. Api2Pdf is a web service that helps you convert html to pdf and runs on AWS Lambda.
Add Header or Footer to PDF with wkhtmltopdf
The advanced options you can primarily use are footerLeft, footerCenter, footerRight, headerLeft, headerCenter, headerRight — all of which take in standard string formats.
Page Numbers in wkhtmltopdf
To add page numbers to your headers and footers, you need to use the [page] and [topage] variables. Most commonly, you will set a footerRight with the text “Page [page] of [topage]”
The following is an example payload of how you would add a footer with page numbers in wkhtmltopdf using the Api2Pdf.com service.
You can learn more about Api2Pdf by visiting its documentation here.Tags: page numbers, pdf, pdf-generation, wkhtmltopdf