Rotate PDF
Operator: Abdulla Al Fahad. How tools are built and checked
Turning a page in a PDF is a one-line change to the file. Every page object may carry a /Rotate entry, a multiple of 90 that tells the reader how far to turn the page clockwise when displaying or printing it. Rotate PDF edits that entry on the pages you choose and saves the document, so a scan that came in sideways, a landscape table in a portrait report or a whole file that was photographed upside down displays the right way up in any viewer, with no re-rendering and no loss of text, links or form fields.
Choose 90° clockwise, 180° or 90° counter-clockwise, leave Pages at all or list the pages to turn, and the rotated copy is produced as soon as the file is chosen, then again each time you change an option. The download is named report-rotated.pdf after the source and the summary states how many pages were turned and which way.
Key features
- Turns every page or only the listed pages by 90° clockwise, 180° or 90° counter-clockwise.
- Writes the standard /Rotate entry so any PDF reader, browser or print dialog honours the change.
- Adds to a page's existing rotation modulo 360, so pre-rotated scans end up where you expect.
- Edits the document in place: text stays selectable, and bookmarks, links, form fields and metadata survive.
- Runs on file choice and on every option change, with a summary such as 3 pages rotated 90° clockwise and a first-page preview.
What rotating changes in the file
The content of a PDF page, its text and drawing instructions, lives in a coordinate space defined by the page's MediaBox, and that is left untouched. Rotation is applied by reading each selected page's current /Rotate value, adding the chosen angle and storing the result modulo 360. A page with no rotation becomes 90; a page already at 90, which many scanners write for landscape sheets, becomes 180 after 90° clockwise, or 0 after 90° counter-clockwise. The counter-clockwise choice is stored as 270, because the PDF value is always clockwise; the summary names the choice you made, so it reads rotated 90° counter-clockwise.
Because only this one entry changes, the file stays almost exactly the same size: a 4,169-byte test file grew to 4,241 bytes, the difference coming from the updated modification date and the rewritten object layout. Fonts, images, annotations, bookmarks, metadata and any form fields are preserved because the document is edited in place rather than rebuilt, and text remains selectable and searchable.
Pages outside the selection are untouched, including whatever rotation they already had. The selection uses the same range syntax as the other page tools: all or an empty box means every page, 1-3, 5 picks specific pages, and 9- runs to the end. Pages are numbered as a reader counts them from 1, not by any numbers printed on them.
How it works
After the usual header and 50MB checks, the document is parsed in memory with pdf-lib. The Pages box is turned into an ascending list of page numbers, with errors for anything below 1, above the page count, or not shaped like a number or a range. For each listed page the tool reads the current rotation angle, adds the chosen angle, normalises the sum into 0 to 359 and writes it back with setRotation.
The file is then written with object streams, a fresh modification date and this site's name as producer; everything else in it is kept as parsed. The output bytes are offered as report-rotated.pdf, the first page is rendered with pdf.js for the preview, and the summary shows pages in and out (always equal), the size before and after, and the count of pages rotated with the turn you chose.
Common use cases
- A receipt or form that was scanned sideways on a flatbed and needs to display upright before it is filed with an expense claim.
- A portrait report with two landscape spreadsheet pages that should be read without tilting the screen; list just those pages and leave the rest alone.
- A batch of photographed documents from a phone that all came out upside down, fixed in one pass with 180° and Pages set to all.
- A PDF exported from a design tool with every page flagged at 90 that should return to its stored orientation using 90° counter-clockwise.
How to use this tool
- Pick the turn under Rotation: 90° clockwise, 180° or 90° counter-clockwise. It can be set before the file is added.
- Then add the PDF; every page is turned straight away with the current setting and the preview updates.
- To rotate only some pages, type them in Pages, for example 3 or 2, 5-7, and press Enter to run without waiting for the short pause.
- The chip reads, for example, 3 pages rotated 90° clockwise; Download .pdf saves report-rotated.pdf.
Example
Source and settings
survey-scan.pdf — 6 pages
Page 4 already stored with /Rotate 90 (scanned landscape)
Rotation: 90° clockwise
Pages: 4-6Result
survey-scan-rotated.pdf — 6 pages
Pages 1-3: /Rotate unchanged (0)
Page 4: 90 + 90 = 180
Pages 5-6: 0 + 90 = 90
Summary: 6 pages in · 6 pages out · 3 pages rotated 90° clockwiseTips for best results
- Changing the Rotation option does not stack. Each run starts from the file you chose, so switching from 90° clockwise to 180° gives you 180° in total, not 270°; for a three-quarter turn choose 90° counter-clockwise.
- To turn different pages in different directions, rotate the first group, download the result, and rotate the second group in the downloaded file; the second run adds to the first.
- The preview shows page 1 of the result, so it only reflects the change when page 1 is among the rotated pages; for other pages, rely on the pages rotated chip and open the download.
- Rotate before adding page numbers or watermarks: those tools place their text in the visible frame of a rotated page, so turning first keeps the stamp at the visible bottom.
Common pitfalls
A rotated page is still the same size in the file, so a Letter portrait page turned 90° is treated by readers and print dialogs as landscape; check the orientation setting before printing.
Check the preview before downloading when a page was scanned sideways: the file may already carry a 90 rotation, and adding 90° clockwise turns it upside down. 90° counter-clockwise brings such a page upright.
Rotation does not straighten a crooked scan. A page scanned a few degrees off stays skewed, because only multiples of 90 exist in the /Rotate entry.
Common errors and how to fix them
- This PDF has 6 pages, so page 7 does not exist.
- The Pages box names a page beyond the end. Use the count given in the message, or write an open range such as 4- to mean 'to the last page'.
- "3–5" is not a page or a range. Use numbers like 1-3, 5, 8.
- The separator between the numbers is not a plain hyphen; en dashes pasted from documents, bare spaces and semicolons all fail. Retype the range with a hyphen and separate entries with commas.
- Page numbers start at 1.
- A 0, or a range beginning at 0, was typed. Readers count pages from 1, so the first page is 1 and 0-3 should be 1-3.
- This PDF is password-protected. Open it with Unlock PDF first, then try again.
- The document cannot be parsed without its password, so no page in it can be turned. Remove the password with Unlock PDF and rotate the unlocked copy.
Best practices
- Rotate first, then number, watermark or merge, so the later tools work on pages whose display orientation is already correct.
- Keep Pages as narrow as possible. Listing only the sideways pages avoids turning correct pages by accident and keeps the summary count meaningful.
- Open the download once in a viewer and scroll to a rotated page; the preview shows only page 1.
Display rotation versus rotated content
There are two ways a PDF can show a page sideways. The content itself may be drawn sideways, as happens when a scanner writes a landscape sheet into a portrait-shaped page, or the page can carry a /Rotate instruction that turns correctly drawn content for display. This tool changes only the instruction. That is the right choice for the common cases: it is lossless, reversible by rotating back, and understood by every reader, since the entry has been part of the format for decades.
It also explains the one thing the tool cannot do. If a page's content is drawn sideways and already flagged with a rotation that compensates, the page looks correct and needs nothing; if the flag is missing, adding it fixes the display. What cannot be fixed this way is content that is skewed by a few degrees or placed off-centre, because /Rotate only accepts multiples of 90. Tools that rewrite the content stream can handle that, at the cost of re-rendering; for upright but turned pages, editing the entry is simpler and safer.
Frequently asked questions
Will the text still be selectable after rotating?
Yes. The page content is not redrawn; only the page's rotation entry changes. Readers select, search and copy text exactly as before, and screen readers see the same text.
What does the PDF store for 90° counter-clockwise?
270. The format only stores clockwise angles, so a quarter turn to the left is written as three quarter turns to the right. The summary still reports the choice you made, and every reader shows the same upright page.
I rotated by 90° but the page is still wrong. What happened?
The page probably already carried a rotation, so the result is a half turn away from what you wanted. Choose 90° counter-clockwise instead, or 180° if it now appears upside down; each run starts from the original file.