PDFPipe

It paginates wrong

Page numbers are missing or all show 1

Either the page number area is empty, or every page says the same number, usually 1 of 1.

What is actually happening

Page numbers come from the footer template's special classes, not from CSS counters in the document body. A CSS counter(page) in the body has no page context to count. The all-ones case usually means the number is in the body rather than the footer.

Confirming it is this and not something that looks like it

Look at where the number lives. If it is in your document markup rather than in the footer template, that is the whole explanation.

The fix

Put the page number in the footer template using the pageNumber and totalPages classes, which the renderer substitutes per page. Leave the document body out of it.

html
<!-- footerTemplate, not document body. The classes are substituted per page. -->
<div style="font-size:9pt;font-family:sans-serif;width:100%;padding:0 16mm;
            display:flex;justify-content:space-between;color:#555">
  <span>Statement for March 2026</span>
  <span>
    Page <span class="pageNumber"></span> of <span class="totalPages"></span>
  </span>
</div>

If that was not it

These produce the same symptom often enough to be worth ruling out before assuming the fix above did not work.

  • displayHeaderFooter left off, which makes the templates inert
  • The classes misspelled, which fails silently rather than erroring
  • A bottom margin too small to show the footer at all
  • Wanting the number to start at something other than 1, which the footer template cannot do arithmetic for

Frequently asked

Does this happen with every rendering engine?

The behaviour behind it is not specific to one tool. Page numbers come from the footer template's special classes, not from CSS counters in the document body. Anything rendering HTML to a paged medium has to make the same decision, so the fix travels with you if you change how the render happens.

Will this show up as an error in my logs?

No, and that is what makes it expensive. A document that renders wrong is still a successful render as far as every log line is concerned. It is found by someone opening the file, which is usually the customer.

Related failures

Problems people arrive at from the same starting point, or mistake for this one.

Paste your markup and see the rendered document, without signing up.