Published on

How to Rotate a PDF on Linux

Authors

Today I wanted to rotate the scan of a pdf that scanned upside down. Tools like Adobe PDF Reader can do this - but you need the paid version. Luckily I have WSL setup with Ubuntu on Windows.

After a bit of Googling, I found that an opensource command-line tool pdftk can do PDF rotations.

Install pdftk

This used to be easy to install on older versions of Ubuntu using apt but it has been removed from the software repositories. Luckily it can still be installed from source fairly easily.

Install from Source

Follow the comprehensive steps from this answer specifically the "Install from source" section

Alias the Jar

Once you have built the jar, create a folder in your home directory called jars (the name can be anything):

mkdir -p ~/jars

Then update your relevant rc file to include the following alias:

alias pdftk='java -jar ~/jars/pdftk.jar'

Source your rc file and now you should be able to run pdftk from the command-line.

Rotate the pdf

To rotate the pdf we need to understand how the pdftk cli works.

This answer has a really good explanation of this:

   pdftk input.pdf cat 1-endsouth output output.pdf
#        \_______/     \___/\___/        \________/
#        input file    range  |          output file
#                           direction

The different directions are based on the above answer and this one:

DirectionDegree Rotation
north0
south180
east90
west270
left-90
right+90
down+180