Wednesday, May 11, 2011

How to rotate pages in a PDF document

I recently scanned quite a number of documents only to discover that every other page was rotated 180 degrees. (Let's just say that I learned my lesson and will be doing a test run before committing time to a task like that. :)

So I searched for a way to be able to selectively rotate pages in a PDF document. As always, I like command line tools that are open source.

Enter pdftk - The PDF toolkit.

To solve my particular problem, the command is:



pdftk input.pdf cat 1 2S 3 4S output output.pdf


Here's a brief explanation:

cat - assembles the pages mentioned
1 2S 3 4S - these are the pages needed. I couldn't find an easy way to say rotate only the even pages but still print out the odd pages, so I had to enumerate the pages
output - specifies the output filename

1 comment:

Jon Eliot said...

Thanks for the tip.
More generic code, to turn every other page regardless of the number of pages. Assumes the first page and all odd-numbered pages are right way up, the other pages are to be rotated 180 degrees.

pdftk orig.pdf cat 1-endevenD output even.pdf
pdftk orig.pdf cat 1-endodd output odd.pdf
pdftk A=odd.pdf B=even.pdf shuffle A B output new.pdf