Clioos › Guides › Add Page Numbers

How to Add Page Numbers to a PDF

By Clioos 团队

The free offline way is an overlay stamp: draw “Page N of M” on a blank page with ReportLab, then merge that overlay onto each real page with pypdf. Tested 2 November 2026 with pypdf 6.21.4 and ReportLab 5.1.0 — a 2-page PDF became a 2-page, 1,949-byte PDF stamped “Page 1 of 2” and “Page 2 of 2”, and pdftotext read both stamps back. That last check matters: the stamps are real, selectable PDF text, not burnt-in images. Clioos does not offer a page-numbering tool — this guide teaches the method.

At a glance

Steps

  1. Install both libraries: pip install pypdf reportlab (pypdf 6.21.4, ReportLab 5.1.0 in the test).
  2. For each page i of N, build an overlay canvas at the page size and draw Page i of N centred at the bottom (36 points up in the test).
  3. Merge with page.merge_page(overlay), add the page to a PdfWriter, and write numbered.pdf.
  4. Verify: the test input (2 pages) became numbered.pdf, 2 pages, 1,949 bytes — and pdftotext returned “Page 1 of 2” and “Page 2 of 2”. If a stamp is missing, the merge step for that page did not run.

Worked example (tested 2 November 2026)

Test input: a 2-page text PDF. Method: ReportLab overlay + pypdf merge_page, stamp centred 36 points from the bottom edge.

FileDetail
sample-text.pdf (input)2 pages, no numbers
numbered.pdf (output)2 pages, 1,949 bytes, stamped “Page 1 of 2” and “Page 2 of 2”
Verificationpdftotext extracted both stamps — the numbers are real text, not images

Page count did not change: stamping adds a text layer to existing pages, it does not add pages.

What it can't do

Frequently asked questions

Is it free to add page numbers to a PDF?

Yes, with pypdf and ReportLab — free and open source, no per-file charge.

Are the stamped numbers searchable?

Yes. In the test, pdftotext extracted “Page 1 of 2” and “Page 2 of 2” — the stamps are real PDF text.

Will stamping change my page count?

No. Each stamp merges onto an existing page; the test went from 2 pages to 2 pages.

Can I start numbering at a different number?

Yes — draw whatever text you want on the overlay (for example “Page 5” on the first stamped page). The script controls the text, not the tool.


Related guides: How to convert PDF to text · How to edit a PDF · How to merge PDF files · All guides · Tool: PDF Probe