Home
Rotate Left and Rotate Right in SumatraPDF turn the pages on screen only. To save rotated pages in the PDF file, so every viewer shows them turned, run a short script with sumatrapdf-tool run.
Available in pre-release 3.7
To fix sideways pages permanently, run rotate-pages.js (below) on the PDF. At a glance:
  • Rotate the view: [ / ], View → Rotate Left / Rotate Right. The file is not changed.
  • Rotate pages in the file from SumatraPDF: Ctrl + K, Run PDF Script…, example Rotate PDF pages permanently
  • Rotate all pages in the file: sumatrapdf-tool run rotate-pages.js in.pdf out.pdf 90
  • Rotate some pages: sumatrapdf-tool run rotate-pages.js in.pdf out.pdf -90 2,5-7
  • Turn upside-down back sides of a scan: sumatrapdf-tool run rotate-pages.js in.pdf out.pdf 180 even

Rotate the view in SumatraPDF #

Use any of these:
  • View → Rotate Left or View → Rotate Right
  • the Rotate Left / Rotate Right toolbar buttons
  • [ rotates left (counterclockwise) and ] rotates right (clockwise). Ctrl + Shift + - and Ctrl + Shift + + do the same, and so do / and * on the numeric keypad
  • Ctrl + K, Rotate Left or Rotate Right in Command Palette (CmdRotateLeft, CmdRotateRight)
Each press turns all pages of the document by 90 degrees. The rotation only changes how SumatraPDF shows the document:
  • The PDF file is not changed. Other PDF viewers, and other people you send the file to, see the original orientation.
  • SumatraPDF remembers the rotation for that file and uses it next time you open it. It is saved as Rotation in FileStates in the settings, when RememberStatePerDocument is true (the default).
  • Printing pages doesn’t use it. To turn the printout, use Rotate printout in the print dialog. See Printing.

Rotate pages in the PDF file #

In SumatraPDF: open the PDF, press Ctrl + K, choose Run PDF Script…, click Example Scripts and pick Rotate PDF pages permanently. Set the angle and the pages, then press Run Script. See Run PDF Script.
From the command line:
  1. Save the script below as rotate-pages.js, or download it.
  2. Run it with the angle and the pages to rotate:
sumatrapdf-tool run rotate-pages.js in.pdf out.pdf 90
out.pdf is a copy of in.pdf with the pages turned. SumatraPDF.exe run with the same arguments works the same.
// Rotate pages of a PDF permanently.
// Info: Rotate PDF pages permanently.
// Arg: <INPUT> : Input PDF
// Arg: <OUTPUT> : New output PDF
// Arg: 90 : Angle clockwise: 90, 180 or 270; -90 turns left
// Arg: all : Pages: all, 2, 1,3-5, 4-N, odd or even (N is the last page)
// Usage: sumatrapdf-tool run rotate-pages.js in.pdf out.pdf [angle] [pages]
// e.g.   sumatrapdf-tool run rotate-pages.js in.pdf out.pdf 90 1,3-5,N

// Settings, used when not given on the command line
var ANGLE = 90; // clockwise: 90, 180 or 270; -90 turns left
var PAGES = "all"; // e.g. "2", "1,3-5", "4-N" (N is the last page), "odd", "even"

if (!scriptArgs[0] || !scriptArgs[1]) {
  print("usage: sumatrapdf-tool run rotate-pages.js in.pdf out.pdf [angle] [pages]");
  quit(1);
}
if (scriptArgs[2]) ANGLE = parseInt(scriptArgs[2]);
if (scriptArgs[3]) PAGES = scriptArgs[3];
if (isNaN(ANGLE) || ANGLE % 90) throw new Error("Angle must be a multiple of 90.");

var doc = Document.openDocument(scriptArgs[0]);
var n = doc.countPages();

// turn "1,3-5,N" into [1, 3, 4, 5, n]
function parsePages(spec) {
  var pages = [];
  spec.split(",").forEach(function (part) {
    part = part.trim();
    if (part == "all") part = "1-N";
    if (part == "odd" || part == "even") {
      for (var p = part == "odd" ? 1 : 2; p <= n; p += 2) pages.push(p);
      return;
    }
    var r = part.replace(/N/g, n).split("-");
    for (var p = parseInt(r[0]); p <= parseInt(r[r.length - 1]); p++) pages.push(p);
  });
  return pages;
}

var done = {};
parsePages(PAGES).forEach(function (p) {
  if (p < 1 || p > n || done[p]) return;
  done[p] = true;
  var pageObj = doc.loadPage(p - 1).getObject();
  var old = pageObj.getInheritable("Rotate");
  var rotate = (old ? old.valueOf() : 0) + ANGLE;
  pageObj.put("Rotate", ((rotate % 360) + 360) % 360);
});

doc.save(scriptArgs[1], "garbage,compress");
print("Saved " + scriptArgs[1]);
The arguments after out.pdf are optional:
  • angle: 90 turns clockwise (right), -90 or 270 counterclockwise (left), 180 upside down. Use a multiple of 90, because PDF doesn’t allow other angles.
  • pages: page numbers and ranges, separated by commas: 3, 1,4-6, 10-N (N is the last page), odd, even or all. Leave it out to rotate every page. A page listed twice is rotated once.
Without arguments, the script uses ANGLE and PAGES from the top of the script.
Examples:
You want Command
Every page to the right sumatrapdf-tool run rotate-pages.js in.pdf out.pdf 90
Page 3 to the left sumatrapdf-tool run rotate-pages.js in.pdf out.pdf -90 3
Pages 2, 5 to 8 and the last page sumatrapdf-tool run rotate-pages.js in.pdf out.pdf 90 2,5-8,N
Upside-down back sides of a two-sided scan sumatrapdf-tool run rotate-pages.js in.pdf out.pdf 180 even
The script sets the rotation (/Rotate) of each page, adding to the rotation the page already has. The page content is not touched, so text, links, bookmarks, annotations and form fields stay as they are. The file size stays about the same.

Rotate with sumatrapdf-tool draw #

sumatrapdf-tool draw can also rotate, without a script:
sumatrapdf-tool draw -R 90 -o out.pdf in.pdf
It draws the pages again into a new PDF and rotates every page it writes. With a page list (... in.pdf 2-4) it writes only those pages. Bookmarks and links are lost, and the file can get much bigger. Use rotate-pages.js instead when you can. See sumatrapdf-tool draw.
Note: merge and clean have no rotate option.

Tips #

  • Write to a new file. Saving over the input file fails with cannot remove file.
  • Rotating pages changes the file, so it breaks existing digital signatures. Rotate before you sign.
  • To rotate many files, run the script in a loop. See Batch process PDFs.

See also #