Skip to content

PDF page numbers, headers and footers

HTML to PDF Page Numbers With Headers and Footers by API

SitePDF adds a running header, a footer and "Page 2 of 7" page numbers to every PDF it renders from your HTML. You pass the header and footer as two small HTML strings and the numbers fill in by themselves.

  • PDF and archive in one call
  • Plans from $49 a month
  • Your HTML stays yours

Short answer

To get page numbers in an HTML to PDF render, send footer_html (and optionally header_html) with the render call and put <span class="pageNumber"></span> and <span class="totalPages"></span> inside it. SitePDF prints that block on every page in managed Chromium, so a 7 page statement reads "Page 1 of 7" through "Page 7 of 7".

Starter API is $49 a month for 10,000 renders ($288 billed yearly). Growth is $99 a month for 50,000 renders and Scale is $299 a month for 250,000.

Written and fact checked by the SitePDF team.

What a header or footer can hold

These are the placeholders Chromium fills in inside header_html and footer_html. SitePDF passes your string through unchanged, so the same rules apply as in a browser print.

Class in your HTML What it prints Typical use
pageNumber The number of the current page "Page 3" in a footer
totalPages The page count of the whole document "of 12" after the page number
date The date the PDF was printed A print date in the corner of a report
title The title of the HTML document Report name in a running header
url The address of the page, when you render a URL Source line on a captured web page

Each of header_html and footer_html is limited to 4,000 characters. Plans and prices are from our own pricing page.

A worked example with a 7 page statement

A finance team sends month end account statements. Each statement runs from 3 to 12 pages depending on the number of transactions, and the customer has to be able to say "page 5 is missing" over the phone. The render call carries the statement HTML plus a footer with the account number and the page counter.

{\n  "html": "<h1>Statement 2026-11</h1>...",\n  "format": "Letter",\n  "margin": "normal",\n  "header_html": "<div style=\"font-size:9px;width:100%;padding:0 15mm;color:#555\">Acme Ltd, account 40-1182</div>",\n  "footer_html": "<div style=\"font-size:9px;width:100%;text-align:center;color:#555\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>"\n}

The statement above renders to 7 pages and the footer reads "Page 1 of 7" to "Page 7 of 7". The account line repeats at the top of each page, so a single loose sheet still says whose it is. At 4,000 statements a month this is 4,000 renders, which fits Starter API.

Three things that make a footer vanish

No font size. The header and footer do not inherit your page CSS. Set font-size inline on the outer element, as in the example, or the text prints too small to see.

Not enough margin. The footer is drawn inside the page margin. The normal preset gives 20 mm top and bottom, wide gives 30 mm, and none gives 0, which leaves no room for a footer. Use normal or an exact value such as 25mm.

Padding on the sides. The footer box spans the full page width, so add your own horizontal padding to line it up with the body text. Our article on margins, headers and footers in HTML to PDF covers the CSS side in more detail.

What it does not do

The same header and footer print on every page. There is no separate first page header, no different layout for odd and even pages, and no restart of numbering per section. If a contract needs a cover page without a number, render the cover and the body as two PDFs and join them in your own code.

Remote images in a header may not load in time, so embed a small logo as a base64 data URI. SitePDF does not stamp a signature or a Bates number onto the file, only the text you provide.

Where it fits next to the rest of the render call

Header and footer are two more fields on the call that already makes the PDF, so they work together with archive and the SHA-256 hash described on the invoice PDF archive page. For SaaS invoices and statements see the HTML to PDF API for SaaS.

When the statement layout is signed off in a short call with the client finance team, a meeting scheduler for client teams saves the back and forth over times. After that the layout lives in your template and nobody touches it by hand.

Who it is for and who it is not for

It is for developers whose product sends multi page documents such as statements, reports, quotes and contracts, and who want the page counter and a repeating account or document line without a PDF library.

It is not for a team that needs per section numbering, a different first page, or roman numerals for a front matter. Those need a typesetting tool such as LaTeX or a layout program, not a browser print.

Render a statement with a page counter in the footer.
curl -X POST https://api.sitepdf.com/v1/render \
  -H "Authorization: Bearer $SITEPDF_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Statement 2026-11</h1>...", "format": "Letter", "footer_html": "<div style=\"font-size:9px;width:100%;text-align:center\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>"}'

This is the documented API call shape. Full request and response walkthrough.

Questions about this job

How do I add page numbers to a PDF generated from HTML?
Send footer_html with the render call and place a span with the class pageNumber and one with the class totalPages in it. Set a font size inline and keep a bottom margin of at least 20 mm so the footer has room to print.
Can I repeat a header on every page of the PDF?
Yes. Send header_html and it prints at the top of every page inside the top margin. It cannot differ between pages, so use it for a document title, an account number or a company line.
Why are my page numbers not showing?
The usual causes are a missing inline font size, a margin set to none, or text colour matching the background. The header and footer do not use your page stylesheet, so style them inline.
Can I leave the page number off the first page?
Not in a single render. The footer prints on every page. Render the cover as its own PDF without a footer and join it with the body in your own code.
How much does it cost?
Starter API is $49 a month for 10,000 renders, or $288 billed yearly. Growth is $99 a month for 50,000 renders and Scale is $299 a month for 250,000. Headers and footers are included on every plan.

Index

More PDF and archiving tools

Get started

Render and archive with one API call

A pixel perfect PDF and a dated copy of the page from the same request. Plans from $49 a month, half price billed yearly.

HTML to PDF, in your browser

Buy the plan