Get your API key
How to rotate PDF pages (free, no software needed)

How to rotate PDF pages (free, no software needed)

Rotate one or all PDF pages permanently for free. Browser tool, macOS Preview, command line, and code options. Files stay on your device.

6 min read

Rotating PDF pages is one of the most common quick-fix tasks: a scanned document came in sideways, a shared file has a landscape page in a portrait report, or a photo was taken in the wrong orientation. The fix takes under 30 seconds with the right tool.

This guide covers every method: browser tool, macOS Preview, command line, and code, so you can pick what fits your workflow.

The fastest way to rotate PDF pages is PDF4.dev's free browser tool. No software, no account, no upload to any server.

  1. Go to Rotate PDF
  2. Upload your file (drag and drop or click to browse)
  3. Select the pages you want to rotate by clicking their thumbnails
  4. Choose the rotation angle: 90°, 180°, or 270° clockwise
  5. Click Rotate PDF and download

Why it works well:

  • Rotation is saved permanently into the file, not just the viewer
  • Works on any page subset, you can rotate page 3 and leave everything else untouched
  • Files are processed by pdf-lib in your browser, they never reach a server
  • No file size limits, no watermarks

Method 2: macOS Preview

If you're on a Mac, Preview can rotate pages without any extra tools.

  1. Open the PDF in Preview
  2. Go to View > Thumbnails to show the sidebar
  3. Click the page thumbnail you want to rotate
  4. Use Tools > Rotate Left (⌘L) or Tools > Rotate Right (⌘R)
  5. Go to File > Export as PDF to save the rotated version

Important: use "Export as PDF", not "Save". The standard Save action does not always write rotation changes permanently. Exporting creates a clean new file with the rotation baked in.

Limitations:

  • macOS only
  • Must export (not just save) to make rotation permanent
  • Batch rotating many pages is tedious via the UI

Method 3: Command line

For scripting or batch processing, command-line tools give you precise control.

Using qpdf

qpdf is the most reliable free CLI tool for PDF rotation. Install with brew install qpdf on macOS or apt install qpdf on Linux.

# Rotate all pages 90 degrees clockwise
qpdf --rotate=+90 input.pdf output.pdf
 
# Rotate all pages 90 degrees counter-clockwise
qpdf --rotate=-90 input.pdf output.pdf
 
# Rotate page 3 only, 180 degrees
qpdf --rotate=180:3 input.pdf output.pdf
 
# Rotate pages 1-3 clockwise, page 5 counter-clockwise
qpdf --rotate=+90:1-3 --rotate=-90:5 input.pdf output.pdf

The + prefix means clockwise, - means counter-clockwise. Page ranges use 1-3, 2,4,6 or z for the last page.

Using Ghostscript

Ghostscript can also rotate pages, though the syntax is less ergonomic:

# Rotate all pages 90 degrees clockwise
gs -dBATCH -dNOPAUSE -dQUIET \
   -sDEVICE=pdfwrite \
   -dAutoRotatePages=/None \
   -c "<</Orientation 3>> setpagedevice" \
   -f input.pdf \
   -sOutputFile=output.pdf

Orientation values: 0 = portrait, 1 = landscape (90° CCW), 2 = portrait (180°), 3 = landscape (270° CCW).

Recommendation: prefer qpdf for rotation. Ghostscript is better suited for compression and format conversion.

Method 4: Code

For developers who need to rotate PDFs as part of an automated pipeline.

Node.js with pdf-lib

import { PDFDocument, degrees } from 'pdf-lib';
import fs from 'fs';
 
async function rotatePdfPages(inputPath, outputPath, pageIndexes, angle) {
  const pdfBytes = fs.readFileSync(inputPath);
  const pdf = await PDFDocument.load(pdfBytes);
 
  for (const index of pageIndexes) {
    const page = pdf.getPage(index);
    const currentRotation = page.getRotation().angle;
    page.setRotation(degrees(currentRotation + angle));
  }
 
  const rotatedBytes = await pdf.save();
  fs.writeFileSync(outputPath, rotatedBytes);
}
 
// Rotate pages 0 and 2 (zero-indexed) by 90 degrees clockwise
rotatePdfPages('document.pdf', 'rotated.pdf', [0, 2], 90);

pdf-lib uses zero-indexed pages (page 1 in the viewer = index 0 in code). The setRotation method takes a degrees() value, which is added to the existing rotation, so calling it twice accumulates.

Python with pypdf

from pypdf import PdfReader, PdfWriter
 
def rotate_pdf_pages(input_path, output_path, page_numbers, angle):
    reader = PdfReader(input_path)
    writer = PdfWriter()
 
    for i, page in enumerate(reader.pages):
        if i in page_numbers:
            page.rotate(angle)
        writer.add_page(page)
 
    with open(output_path, 'wb') as f:
        writer.write(f)
 
# Rotate pages 0 and 2 (zero-indexed) by 90 degrees
rotate_pdf_pages('document.pdf', 'rotated.pdf', {0, 2}, 90)

pypdf is the actively maintained fork of PyPDF2. Install with pip install pypdf. The rotate() method takes an angle in degrees and rotates clockwise.

Rotating all pages in a directory (batch)

from pypdf import PdfReader, PdfWriter
import os
 
def batch_rotate(input_dir, output_dir, angle=90):
    os.makedirs(output_dir, exist_ok=True)
    
    for filename in os.listdir(input_dir):
        if not filename.endswith('.pdf'):
            continue
        
        input_path = os.path.join(input_dir, filename)
        output_path = os.path.join(output_dir, filename)
        
        reader = PdfReader(input_path)
        writer = PdfWriter()
        
        for page in reader.pages:
            page.rotate(angle)
            writer.add_page(page)
        
        with open(output_path, 'wb') as f:
            writer.write(f)
        
        print(f'Rotated: {filename}')
 
batch_rotate('scanned_docs/', 'corrected_docs/', angle=90)

This is useful for bulk-correcting scanner output where all pages come out in the wrong orientation.

Comparing methods

MethodSetupBest forPermanentBatch
PDF4.dev browser toolNoneQuick fixes, any deviceYesManual
macOS PreviewmacOS onlyOne-off edits on MacYes (export)No
qpdf (CLI)Install qpdfScripting, automationYesYes
Ghostscript (CLI)Install GSComplex pipelinesYesYes
pdf-lib (Node.js)npm installApps, APIsYesYes
pypdf (Python)pip installScripts, automationYesYes

Why "rotate in viewer" does not stick

PDF viewers like Chrome, Firefox, and some versions of Preview can rotate a page in the display without changing the file. When you share or reopen that PDF, the original orientation comes back.

This is because the PDF format stores rotation as a metadata flag (/Rotate in the page dictionary). Viewer rotation only changes what the application renders on screen, it does not write the flag back to the file on disk.

To rotate permanently, you need a tool that writes the /Rotate value into the PDF file structure. All methods in this article do that.

Rotate as part of a PDF generation workflow

If you're generating PDFs programmatically (invoices, reports, certificates) and the output comes out in the wrong orientation, fixing it with post-processing rotation is the wrong layer. The better fix is to set the correct page format at generation time.

With the PDF4.dev API, page orientation is controlled via the format parameter:

curl -X POST https://pdf4.dev/api/v1/render \
  -H "Authorization: Bearer p4_live_xxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "my-report",
    "data": { "title": "Q1 Report" },
    "format": {
      "preset": "a4-landscape"
    }
  }'

Available presets: a4, a4-landscape, letter, letter-landscape, square, custom. Setting the correct preset at generation time means no rotation step is ever needed downstream.

For custom dimensions:

"format": {
  "preset": "custom",
  "width": "297mm",
  "height": "210mm"
}

Need to generate PDFs programmatically with correct orientation from the start? PDF4.dev offers a free tier with a visual template editor and REST API. Get started free.

If you need to do more with your PDF after rotating:

Free tools mentioned:

Rotate PdfTry it free

Frequently asked questions

How do I rotate a PDF page permanently?
Use PDF4.dev's rotate tool at pdf4.dev/tools/rotate-pdf. Upload your PDF, select the pages to rotate and the angle (90, 180, or 270 degrees), then download. The rotation is saved permanently into the PDF file.
Can I rotate just one page in a PDF, not all of them?
Yes. PDF4.dev's rotate tool lets you select individual pages by thumbnail and rotate only those. You can also set different rotations per page in the same session.
Is rotating a PDF free?
Yes. The rotate tool at pdf4.dev/tools/rotate-pdf is free and requires no account. Files are processed entirely in your browser.
Does rotating a PDF reduce quality?
No. Rotating a PDF page only changes a rotation flag stored in the file metadata. The actual page content (text, images, vectors) is not re-rendered or recompressed.
Why does my PDF open rotated even after I rotate it in a viewer?
Viewers like Preview and browsers sometimes rotate the display without saving it to the file. Use a dedicated rotate tool to permanently write the rotation into the PDF.
Can I rotate a PDF on a Mac without Adobe?
Yes. Use either PDF4.dev's browser-based tool or macOS Preview (View > Rotate Left/Right, then export as PDF). Preview's rotation does not always save permanently though, so the browser tool is more reliable.
How do I rotate a PDF 180 degrees?
In PDF4.dev's rotate tool, select the pages you want to flip and choose 180 degrees. The page will be upside-down relative to the original.
Can I undo a PDF rotation?
Not within the same session after downloading. Just rotate the file again by 90 or 270 degrees in the opposite direction to get back to the original orientation.
Does rotating a PDF change the file size?
Rotation changes only a metadata flag in the PDF structure. File size stays virtually identical to the original.
How do I rotate a PDF programmatically in bulk?
Use pdf-lib in Node.js or PyPDF2/pypdf in Python to set the rotation property on each page. See the code examples in this article.

Start generating PDFs

Build PDF templates with a visual editor. Render them via API from any language in ~300ms.