Skip to content
Allin

Adding Page Numbers to a PDF When the Pages Are Rotated or Mixed Sizes

Published 8/13/2026 · 14 min read · File tools

Daniel Okonkwo

Daniel OkonkwoFront-end developer and tech writer at Allin

Web performance · File formats

Checked against 3 sources

View profile
In short

A PDF page carries a rotation flag that viewers apply at display time, and a drawing library ignores. That single fact is why most numbering tools put the number sideways, or off the page, on any document that has been turned. This tool undoes the rotation before it places anything: it works out where the corner is on the page as the reader sees it, converts that point back into the page's own unrotated space, and rotates the text to match. Tested across all four rotation values and three page sizes in one file, the number landed 28 points above the bottom of the displayed page every time, horizontally centred on the displayed width, reading left to right — verified by re-reading the output through a rendering engine's own viewport transform, not by trusting the arithmetic. Mixed sizes are handled per page rather than against the first one: in a file holding A4, Letter and landscape sheets, the centred number sat at 287.9, 296.3 and 411.2 points respectively. A print file is measured from its CropBox — the trimmed page a reader sees — rather than from the oversized sheet it is drawn on: at a 1/8-inch bleed and at a 3/8-inch bleed alike, the number still landed 28.00 points above the trim. A starting number other than 1 works, and the {N} placeholder means the last number printed, not the page count — starting at 5 and skipping 2 cover pages of a 6-page file gave “5 / 8” on the first numbered page and “8 / 8” on the last. One thing it cannot do. It never reads the page, so a number already printed there is invisible to it: a test page showing “Page 1 of 2” came back showing that and “1 / 3”, the two disagreeing about how long the document is.

Numbering a tidy document is trivial. The cases that bite are a page turned sideways, a Letter sheet among A4 ones, a print file with bleed, and a document that already prints its own number. All four were tested: on the first three the number lands exactly where you asked, and the fourth is not detected at all.

Rotation is the test most numbering tools fail

A PDF page can carry a rotation of 0, 90, 180 or 270 degrees. The rotation is not baked into the content — the drawing instructions stay exactly as they were written, and the viewer turns the whole page at display time. This is how every scan that came in sideways gets fixed, and it is extremely common in documents that have passed through a scanner or a rotate tool.

The trap is that the library which writes the number does not apply the rotation. Ask it for “bottom centre” on a page turned 90 degrees and it will faithfully put the text at the bottom centre of the unturned page — which the reader sees as the middle of the left-hand edge, lying on its side. On a 270-degree page it lands on the opposite edge instead. Get it slightly wrong on a landscape sheet and the number falls off entirely, because the width and the height have swapped.

This tool does the conversion. A six-page file was built holding A4 portrait, Letter portrait, A4 landscape, and three A4 pages rotated by 90, 180 and 270 degrees, then numbered at bottom centre with a 28-point margin. Reading the result back through a rendering engine's viewport — the same transform a viewer applies — every one of the six numbers sat 28 points above the bottom of the page as displayed, and every one read left to right. On the rotated pages the original body text came back at 90, 180 and 270 degrees in that same view, which is the point: the number is upright precisely because it was corrected, and the page content was not.

Mixed page sizes: each page measured on its own

A merged pack almost never has one page size. An A4 report with a Letter appendix, a landscape spreadsheet printed into the middle of a portrait document, a scan that came out at an odd size — all of these are ordinary. A tool that measures the first page and then reuses that measurement will drift the number sideways on every page that differs.

This one measures each page as it numbers it. In the six-page test file, the centred number sat at 287.9 points on the A4 sheets, 296.3 on the Letter sheet, and 411.2 on the landscape and rotated ones. Those are three different horizontal positions in the file, and all three are the centre of their own page. When several documents are numbered in one pass the same rule applies at the document level: each file's last number is computed from that file's own length, so a five-page chapter reads “5 / 5” even when it is queued behind a forty-page one.

A print file with bleed: measured from the trim, not the sheet

A page has more than one rectangle. The MediaBox is the sheet the page is drawn on; the CropBox is the part a reader is supposed to see. In an ordinary office document they are the same, which is why the difference almost never comes up. In a file prepared for print they are not: the sheet is larger than the finished page, the extra band around the edge is the bleed, and the CropBox marks where the trim will fall.

The tool measures the CropBox, which makes the margin you set a margin from the finished edge — the one the reader will hold. Measured on purpose-built pages, bottom centre, 28-point margin: at a 1/8-inch bleed the number sat 28.00 points above the trimmed edge; at a 3/8-inch bleed, 28.00 points as well; and on a page with no bleed at all, the same 28.00. The three are indistinguishable, which is the point. A page that declares no CropBox is unaffected, because a missing CropBox means the MediaBox by definition — and a sheet whose own origin is not at zero is handled too, since the corner of the box is added back rather than assumed. The on-screen preview is built from that same measurement, so what it shows you is what the file will hold.

The number already on the page is invisible to it

This is worth stating plainly because it disappoints people who expect otherwise: no numbering tool of this kind detects an existing page number, and this one is no exception. It never reads the text of the page at all. It opens the document, adds a drawing instruction to each page, and saves. Whatever was already printed there stays printed there.

The test made this concrete. A three-page file whose first page already carried the footer “Page 1 of 2” was numbered bottom right. The result shows both: the original footer, and a new “1 / 3” sixteen points below it. The two contradict each other on the same page — the old footer counted two pages, the tool counted three — and nothing in the interface hints that this has happened. If your document already prints numbers, either remove them at the source or accept two sets, and check at least one page before you send the file anywhere.

The same blindness applies to anything else already at the margin. A test page carrying a company footer running from 120 to 356 points across the bottom, at the same height the number goes, received its “1 / 1” at 288 to 307 points — printed straight over the address. There is no collision check, and there cannot easily be one without reading the page. Move the number to a corner the document leaves free, or raise the margin until it clears.

What the numbering does to the original pages

Nothing is re-compressed and nothing is re-rendered. The number is added as a new drawing instruction appended to the page, not by rewriting what was there: in a numbered file the page's content grew from eight instruction blocks to eleven, and the original eight were untouched. Every raw data stream in two real documents — 48 in one, 60 in the other, including two embedded images — came out byte-for-byte identical after numbering. Text stays selectable, images keep their original quality, and there is no generation loss.

The file size can move in either direction, and often falls. One Portuguese document went from 152,674 bytes to 74,823 — half the size, with all eight pages and every character of its text intact. The reason is that the whole file is rebuilt rather than appended to: the original carried three revisions stacked on top of one another, and the rebuilt file carries one. That is a side effect of the library, not a feature of the tool, and it is worth knowing because it means the output is not a minimal edit of your original. It is a fresh file containing the same pages.

Two documents will be refused outright. An encrypted PDF is one: the library will not open a file that carries a security handler, even when there is no password to type and the file opens instantly in any reader. A 192-page industry standard used in these tests behaves exactly that way — its text extracts fine with the text tool on this site, and the numbering tool names it and passes over it. The other refusal is a label containing characters the standard PDF font cannot write: Polish, Czech, Turkish, Greek and Cyrillic letters are all outside its repertoire, and the tool checks the label before it starts rather than failing halfway through a batch.

Where the number lands on an awkward page — measured in August 2026, bottom centre, 28-point margin
Page situationWhere the number landsVerdict
A4 portrait, no rotationCentred at 287.9 pt, 28 pt above the bottomCorrect
Letter sheet among A4 pagesRe-centred at 296.3 pt, on its own widthCorrect — each page measured on its own
Landscape page among portraitsCentred at 411.2 pt, on the 842 pt widthCorrect
Page rotated 90, 180 or 270 degrees28 pt above the bottom as displayed, reading uprightCorrect — the page rotation is undone first
Print page with a bleed (1/8 in and 3/8 in tested)28.00 pt above the trimmed edge, on bothCorrect — the CropBox is what is measured
Page already printing its own numberA second number is added below the firstNot detected — the page is never read
Content already at the bottom marginPrinted straight over it, at the same heightNo collision check exists
Number PDF pagesAdd page numbers to a PDF, in the corner and the format you choose. Numbers several documents at once, each against its own length.Try the tool

Frequently asked questions

My pages are rotated. Will the numbers come out sideways?
No. This was tested on all four rotation values in one file and the number came out upright and in the requested corner every time, measured through the same viewport transform a reader applies. The tool works out where the corner is on the page as you see it, converts that back into the page's own coordinate space, and rotates the text by the page's rotation so its baseline still runs the way you read. This is worth checking on any other numbering tool you use, because it is exactly where they go wrong: a number that lands in the middle of the left edge, lying on its side, is the signature of a tool that ignored the rotation flag.
My document mixes A4 and Letter. Will the numbers line up?
Each number will be correctly placed on its own page, which is not quite the same as lining up. A centred number sits at 287.9 points on A4 and 296.3 on Letter, because those are the centres of two different widths — flip between the pages on screen and the number moves. That is right: it is centred on each sheet. If you need them to align across the whole document, use a corner position instead of a centred one, since a fixed margin from the left or the right edge gives the same distance on every page regardless of width. Numbering several separate files in one pass follows the same principle at the document level: each file's total is its own.
The document already has page numbers. Will the tool replace them?
No — it adds a second set. The tool never reads the text on the page; it only draws on top of it. In testing, a page already showing “Page 1 of 2” came back showing that and a new “1 / 3” just below it, the two disagreeing about how many pages the document has. Removing an existing number means going back to whatever produced the document, because once it is drawn into the page it is part of the content like any other text. If you cannot do that, put the new number in a different corner so the two do not sit on top of each other, and tell whoever receives the file which set counts.
Will numbering re-compress my PDF or lose quality?
No. The number is a new drawing instruction appended to the page, and the original content is not touched. Every raw data stream in two real test documents — including embedded images — came out byte-for-byte identical after numbering. Text stays selectable and images keep their exact original data, so you can number the same file repeatedly without any generation loss. The file size may still change, and often drops sharply: the library rebuilds the whole file rather than appending to it, so a document carrying several stacked revisions comes back as a single one. One test file halved in size with all its pages and all its text intact.
Why does it refuse my PDF, or my label?
Two causes. If the file is refused, it is almost certainly encrypted — and encrypted does not necessarily mean password-protected. Many published documents carry a security handler with an empty user password: they open instantly in any reader, but the library used here will not touch them. A 192-page industry standard used in these tests does exactly that, and the same file extracts its text perfectly well with the text tool on this site. Remove the protection at the source and come back. If the label is refused, it contains a character the standard PDF font cannot write. Latin-1 letters are fine — accents, cedillas, umlauts, the section and degree signs, dashes and curly quotes all work — but Polish, Czech, Turkish, Greek and Cyrillic letters do not. The tool checks before it starts, so a whole batch is never lost halfway through.

Articles you may find interesting

All guides
ExplainerYour PDF Looks Straight to You and Sideways to ThemYou rotated the scan, saved it, and the recipient still opened it sideways. Nothing is broken — rotation in a PDF is an instruction rather than a change to the page, and instructions can be ignored. Here is when that happens and how to produce a file that cannot be misread.How-toPutting a Scanned Document Back in the Order It Was PrintedA duplex scanner that took one side at a time, a stack fed upside down, a page that came out twice. Reordering is not the same operation as extracting pages, and knowing which one you are doing tells you what happens to everything that is not a page.How-toExtracting a Few Pages from a Statement Without Installing AnythingA landlord wants page 3. An accountant wants January. You need to send those pages and not the eleven others, and there is a trap: the obvious way leaves the removed pages inside the file you send.How-toMerging an Application Pack into One PDF, in the Right OrderA rental file, a loan application, a tender: the requester wants one document, in the order they listed. The merge itself takes seconds. What goes wrong is the ordering, the page sizes and the file that silently loses its signature — all of which are avoidable if you know where they bite.How-toSending a Document for Signature: the Workflow, Not the LawWhether a drawn signature is valid is settled elsewhere. What decides whether your document actually gets signed is the order you ask people in, what the audit trail records, and six failure modes that have nothing to do with the law.GuideWhat a PDF Says About You: Reading and Clearing Its MetadataA PDF carries its metadata twice, in two stores that can tell different stories, and neither of them is the whole story. Here is what is actually in the file, what clearing it removes, and the two things that survive every wipe.

Related tools

Everything described here was measured in August 2026 by running these tools on real files, not inferred from what a PDF tool ought to do. PDF behaviour is not uniform: the file format is defined by ISO 32000, but reading order, metadata conventions and page boxes are all places where two correct-looking tools disagree, and a file written by an unusual producer can behave unlike every file tested here. Before you run any of this over a document you cannot replace, work on a copy and open the result in a reader you trust.

Sources

Spotted a mistake in this article?