To add both the current page and the total number of pages in a PDF header or footer, type the lowercase tokens {page} and {pages} into the header or footer text box — {page} becomes the current one-based page number on each page, and {pages} becomes the total structural page count. A footer reading "Page {page} of {pages}" therefore renders as "Page 2 of 5" on page two of a five-page PDF, "Page 3 of 5" on page three, and so on. Replacement is deterministic and applies wherever the exact lowercase token appears in the field. The {page} token is replaced on every page with its own number, while {pages} resolves to the same total on every page. Anything else inside curly braces is left untouched, so a stray {Year} in your footer stays as {Year}. Numbering always begins at one, and the total always reflects the source document before any text is added, which keeps the output predictable. The whole job runs locally in your browser, so the source file and the stamped copy are not uploaded.

how do i add current and total page numbers when i use header footer add header footer to pdf
Add Current and Total Page Numbers to a PDF Header

What {page} and {pages} actually resolve to

The two placeholders are designed for simple page numbering and nothing else. {page} is a one-based counter that walks the structural pages of the source PDF in order, starting at 1 on the first page, 2 on the second, and so on. {pages} is a static value — the total number of pages in the original document — and it shows the same number on every page. Replacement happens at render time, so the text you see in the field is not literally stored in the output; what is stored is the expanded string for each page.

Both tokens are matched exactly and case-sensitively. {PAGE}, {Page}, and {pages} are three different strings to the engine; only {page} (lowercase) and {pages} (lowercase) expand. If you type {Year}, {Filename}, or any other bracketed text, it is preserved verbatim in the output. This is useful when you want to keep a placeholder visible in the field while still letting the real tokens expand.

There is no starting-number offset. Page one of your source PDF always renders as page one in the stamped copy, and the total never reflects the new stamped document — it always reflects the original page count that was used when the file was created. This is why a footer reading "Page {page} of {pages}" stays correct even after you trim, rotate, or rearrange the file later: the {pages} value is locked to the page count the engine saw when it stamped.

Because the engine only recognizes {page} and {pages}, your footer can use any wording that combines those two tokens with regular text. The header and footer fields each accept up to 120 Unicode characters after trimming, which is enough for the common patterns shown below.

The following table shows exactly how each pattern expands on different pages of a five-page source PDF. The "Input" column is what you type into the header or footer field; the other columns are what appears on each stamped page.

Input you typePage 1Page 2Page 3Page 4Page 5
Page {page} of {pages}Page 1 of 5Page 2 of 5Page 3 of 5Page 4 of 5Page 5 of 5
{page} / {pages}1 / 52 / 53 / 54 / 55 / 5
- {page} -- 1 -- 2 -- 3 -- 4 -- 5 -
Confidential — page {page}Confidential — page 1Confidential — page 2Confidential — page 3Confidential — page 4Confidential — page 5
{Year} — {page} of {pages}{Year} — 1 of 5{Year} — 2 of 5{Year} — 3 of 5{Year} — 4 of 5{Year} — 5 of 5

The last row is the one to remember: only {page} and {pages} expand. Anything else in braces stays exactly as you typed it.

How to stamp "Page X of Y" on every page

The cleanest path is a focused tool rather than a full PDF editor, especially when the only change you want is a centered page-number footer. Header Footer PDF takes a local PDF, draws one optional header line and one optional footer line on every structural page, and saves a new copy without uploading the source. Here is the exact sequence for the "Page {page} of {pages}" case.

  1. Open Header Footer PDF in your browser. No sign-up, no install.
  2. Choose the source PDF from your computer. The file must be a non-empty PDF no larger than 25 MiB.
  3. Leave the Header field empty, or fill it with a separate label such as "Confidential" if you want both lines.
  4. Type Page {page} of {pages} into the Footer field. The two tokens are lowercase and case-sensitive — keep them exactly as shown.
  5. Pick a font size (whole points from 6 to 36) and an edge margin (whole points from 0 to 200). Start with 9 pt and 24 pt if you are unsure.
  6. Click Add header and footer. The browser expands each token per page, draws the line at the requested margin, and saves a new PDF locally.
  7. Download the stamped file. The new filename keeps your source base name and adds -header-footer.pdf, so report.pdf becomes report-header-footer.pdf.
  8. Open the downloaded PDF and jump to page two. You should see "Page 2 of 5" centered above the bottom edge for a five-page source.

If you typed both a header and a footer, the header is placed below the top edge by the chosen margin plus the font size, and the footer starts above the bottom edge by the same margin. Both lines are horizontally centered using the real text width measured against the embedded standard Helvetica font, as documented in the pdf-lib drawText API.

What stays the same across every page

The tool stamps every structural page uniformly — there is no built-in rule that treats page one as a cover, no Roman-numeral mode, and no way to alternate content between odd and even pages. If you fill in the Footer field, every page gets the same line with the same tokens, and only {page} changes as you scroll. This uniformity is intentional and makes the result easy to verify: open the stamped PDF, jump to the last page, and confirm the footer reads "Page N of N."

The source page boxes, page order, existing visible content, and original page count are preserved. The new text is drawn as additional PDF content rather than as a viewer-only overlay, so it is part of the file, not a temporary mark. Existing content near an edge can overlap the chosen line because the tool does not push the body text down, reflow paragraphs, detect a safe margin, or move logos and crop marks out of the way automatically. If your source already has a footer at the bottom, adding a second footer will paint on top of it.

Limits, overflow, and the 6-point floor

A few hard limits shape what the tool can stamp, and they are worth knowing before you finalize a footer.

SettingAccepted rangeBehavior at the boundary
Font sizeWhole numbers from 6 to 36 pointsIf a line is wider than the usable page width, size is reduced one point at a time down to 6. Text is never stretched, wrapped, or silently deleted.
Edge marginWhole numbers from 0 to 200 pointsHeader sits below the top edge by margin plus size; footer sits above the bottom edge by the same margin.
Text per fieldUp to 120 Unicode characters after trimmingEach text field is trimmed and limited to 120 Unicode characters.
Source fileNon-empty PDF up to 25 MiBEncrypted, damaged, oversized, or mislabeled files produce a visible error and are not bypassed.
Embedded fontStandard HelveticaPractical Latin character set only. Files fail visibly if the entered text cannot be encoded, which prevents silent character substitution.

The most common failure mode is a footer that is too long for a narrow page or for a large margin. The tool does not wrap or shrink text behind your back in any other way — it only steps the font size down to the 6-point floor, then either fits or fails. So when the output looks crowded, shorten the footer text or reduce the margin before stamping again. Any setting change also revokes the previous download, so a stale file cannot be mistaken for a newer configuration. For the Latin-only limit, the StandardFonts reference lists which glyphs are actually available.

When {page} and {pages} are the right tool for the job

This approach is a good fit for straightforward centered labels — page numbers like "Page 2 of 5", confidentiality notices, filenames, revision names, and similar one-line stamps — where the document already has enough margin to fit the text. It also fits cleanly when the file should never leave your computer: loading, font embedding, drawing, saving, and download creation all happen in the browser, and nothing is sent to a server.

It is the wrong fit when you need Bates numbering, Roman-numeral prefaces, multi-line headers, images, dates, hyperlinks, different odd/even content, a cover-page exclusion, or a custom embedded font for non-Latin branding. For those cases, a desktop publishing application with full font-licensing and layout control is the right layer. If you want a deeper look at how labels and page numbers stack up in this kind of local stamping workflow, the PDF header and footer adder guide walks through the same tool from the label-and-number angle.

If you're weighing options, Avoid Mistakes When You Add a Header and Footer to a PDF covers this in detail.