When I scan documents that are landscape oriented, the output PDF files are portrait and so all the PDF viewers display the scanned documents in portrait.

From the command line, how do you rotate a PDF file 90 degrees?

I tried searching and found a bunch of solutions but I had trouble finding what looked like an authoritative solution[1] that uses a stable/robust linux/unix tool.

footnote [1]

For example, here is a sampling of some of the haphazard solutions I found:

  • "just use Adobe Acrobat Pro to rotate the file and then save the file"
  • "use pdfjam"
  • "use pdftk"
  • "use ${PROGRAM_NAME} from Poppler"
  • "use Imagemagick's convert" -- but then all the comments were very negative and stating "the image quality is ruined"
  • "open the file in a PDF viewer, then rotate, then print using a PDF printer like CUTEPDF or PDFPRINTER or etc"
  • "use ${PROGRAM_NAME}" then i searched for "${PROGRAM_NAME}" and there is something about "Fedora removed ${PROGRAM_NAME} because of licensing issues"
  • 5
    There are no "authorative solutions", but you should keep in mind what method the various solutions use: Direct manipulation of PDF structure (pdftk, Adobe Acrobat, and other programs), converting to an image and then converting back to a PDF (e.g. Imagemagick's convert, printing using PDF printer etc.). The latter is obviously a bad idea. – dirkt Sep 24 '17 at 5:38
  • How are those haphazard solution? How were you disappointed by each one of them? Did you actually try them? – simlev Sep 16 '18 at 1:31

Just use pdftk.

  1. For rotating clockwise:

    pdftk input.pdf cat 1-endeast output output.pdf
  2. For rotating anti-clockwise:

    pdftk input.pdf cat 1-endwest output output.pdf

Regarding the installation of pdftk on Fedora, I found this link.

| improve this answer | |
  • 6
    The man page of pdftk states more options for rotating: The page rotation setting can cause pdftk to rotate pages and documents. Each option sets the page rotation as follows (in degrees): north: 0, east: 90, south: 180, west: 270, left: -90, right: +90, down: +180. left, right, and down make relative adjustments to a page's rotation. – Tapper May 8 '18 at 20:21
  • Output is rotated but still scaled small enough to fit the original orientation. Not helpful. – JohnMudd May 10 '18 at 20:13
  • @JohnMudd What do you mean by "scaled small enough to fit the original orientation" ? I suppose you now have a problem with the PDF viewer, not with the rotation of pages. – user163859 May 12 '18 at 9:40
  • My original PDF was a letter size page rotated 90 degrees so page height was reduced from 11" to 8.5". Didn't change after correcting rotation. Found this to be true with many online tools. Might not be a problem with conversion after all. I found a scaling option while viewing/printing rotated PDF and that fixed it. Sorry, I was so frustrated at that point that I just printed and moved on and didn't note the exact steps I took. – JohnMudd May 14 '18 at 9:29
  • 1
    pdftk is removed in Ubuntu 18.04 and above. Ubuntu itself suggests to install a snap, which works only in simple situations (it did not find my files, perhaps because they were outside of my home directory ?). I moved to pdfjam ... --angle 270.... – Stéphane Gourichon Jan 7 '19 at 18:13

I just stumbled upon this thread and saw that there is no good solution mentioned yet. I found that (at least on Debian and Ubuntu) pdfjam comes with the following commands:

pdf90 input.pdf
pdf180 input.pdf
pdf270 input.pdf

I think that is the easiest and fastest approach. These are scripts using the pdfjam command properly. Btw. the pdfjam is a virtual package that comes with texlive-extra-utils

| improve this answer | |
  • 6
    Looks like 90 goes counterclockwise and 270 goes clockwise - perhaps you should mention that. – Aaron Hall Dec 26 '18 at 18:33
  • 3
    pdf90 is indeed a thin wrapper. Yet it forces a suffix convention. So I used pdfjam directly: pdfjam --outfile myoutputfile.pdf --angle 270 --fitpaper true --rotateoversize true myinputfile.pdf – Stéphane Gourichon Jan 7 '19 at 18:15
  • 1
    you can also change the suffix using the argument --suffix desired_suffix. Default is : --suffix rotated90 so the output is : initial_name-rotated90.pdf – jeannej Apr 27 at 17:45

In Linux Mint 18.3 (I believe in other Debian derived distributions as well) you have a simple command line tool named qpdf.

You can use: qpdf in.pdf out.pdf --rotate=[+|-]angle[:page-range].

From the documentation:


Apply rotation to specified pages. The page-range portion of the option value has the same format as page ranges in Section 3.5, “Page Selection Options”. If the page range is omitted, the rotation is applied to all pages. The angle portion of the parameter may be either 90, 180, or 270. If preceded by + or -, the angle is added to or subtracted from the specified pages' original rotations. Otherwise the pages' rotations are set to the exact value. For example, the command qpdf in.pdf out.pdf --rotate=+90:2,4,6 --rotate=180:7-8 would rotate pages 2, 4, and 6 90 degrees clockwise from their original rotation and force the rotation of pages 7 through 9 to 180 degrees regardless of their original rotation, and the command qpdf in.pdf out.pdf --rotate=180 would rotate all pages by 180 degrees.

| improve this answer | |
  • 3
    Specifying the page-range seems to be compulsory, at least in my current qpdf version (8.0.2). – Xtreme Biker Mar 27 '19 at 9:58
  • It seems at least not to be the case anymore (9.0.2): qpdf in.pdf out.pdf --rotate==-90 works well for all pages. – iNyar Nov 8 '19 at 15:30
  • The only solution that worked for me. All others I tried didn't work. pdftk didn't produce any output. pdf90 and friends would require 192MB of space for all texlive-extra-utils stuff. I only had to tweak the command line a bit. As stated above, page is mandatory. I used this: qpdf input.pdf output.pdf --rotate=90:1 – Alexandre Schmidt May 4 at 18:07
  • Page doesn't seem to be mandatory to me (8.4.2), but I had to put the parameter before input and output: qpdf --rotate=90 input.pdf output.pdf. In any case, that's easy to figure out and the package itself is only a few hundred kilobytes, so it's the best option IMO. – Ale Jun 10 at 9:36

You can use ImageMagick: display or convert - e.g. to rotate it clockwise use

convert -rotate 90 <file>.pdf <rotated-file>.pdf

Use -90 for a counterclockwise rotation.

N.B. Only use this method when the original image is a bitmap (e.g. produced by scanning). If the original image is not a bitmap, this method will convert it to one and quality will suffer. In the latter case, please use one of the methods in the other answers.

| improve this answer | |
  • 12
    This will first convert the PDF text to an image, so size will increase and quality will drop (Unless it was already only a scan). – aviv Nov 8 '17 at 12:55
  • 1
    Yes indeed, that is a useful reminder, but in this case the OP states that he is scanning the documents. – NickD Nov 8 '17 at 21:46
  • 13
    Result pdf is very low quality. – Ivan Romanov Mar 4 '18 at 11:05
  • This method is good only for scanned originals: they are already bitmaps. For ordinary PDFs, see @aviv's comment above and maybe use the method in the other answer. – NickD Mar 4 '18 at 18:36

pdftk is no longer available on Ubuntu 18.04 due to some deprecated dependencies.

The best solution I found was the (graphical) tool pdfshuffler.

Install and run it. Open the desired pdf file, right click on the page, and rotate each one individually. It also collate pdfs and some other nice things.

sudo apt install pdfshuffler
| improve this answer | |
  • 1
    Do you have to rotate each page manually? That's a deal breaker. I need to rotate a hundreds-page-long PDF book to view it better (larger) on a Kindle. UPDATE: Just tried it, nope, you can Ctrl-A to select all pages then rotate them all in one step. – Gerry Lufwansa Aug 7 '18 at 2:51
  • 1
    sudo snap install pdftk works just fine on Ubuntu 18.04. There is more usage info in this answer. – Acumenus May 26 at 0:24

To improve output resolution (default is 72 DPI), I got good results with:

convert -rotate -90 -density 200 input.pdf output.pdf

This was for a .pdf of a scanned document. I found that -density 300 reduced quality somewhat versus -density 200.

| improve this answer | |
  • Adding -density 300, 600 and even 1200 had only slight improvement on output quality. – JohnMudd May 10 '18 at 20:20

Although it does have its limitations, I quite often use PDFedit, especially for the rotation of PDF scans. While ImageMagick's convert (using rather high -density values) achieves quite a good quality, it also bloats the file (original: 155 kiB, 180° rotated copy: 1.2 MiB). PDFedit rotates the same image with unchanged quality without noticably changing the file size.

| improve this answer | |
  • sounds very promising! i also noticed the issue with changing the file size drastically that you refer to. – Trevor Boyd Smith Apr 17 '18 at 14:47

I use this command to automatically rotate pdf files to become upright down if they aren't upright in the first place :

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/All -sOutputFile="$outputFile" "$file"
| improve this answer | |
  • This had zero effect. – Colin 't Hart Aug 16 '18 at 14:09
  • @Colin'tHart My command only restores the document to become upright down if it wasn't upright in the first place, to force the rotation use pdf90 or pdf180 or pdf270 instead, see this answer – SebMa Aug 17 '18 at 12:02
  • This worked for me. I guess it may work for some PDF documents not for others. – Simon Kissane May 25 at 0:43

Not the solution for this question but i found a way to rotate without installing softwares or using another websites

Ubuntu comes with pdfimages that convert a pdf to image

pdfimages input.pdf output

Ubuntu also comes with Images Viewer that let you view, rotate and print to pdf your image

  • Open image with Image Viewer
  • Press the rotate button at bottom center
  • Ctrl+P to print the image to pdf
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.