My *nix world

How to rotate even odd scanned PDF pages

Sometimes you need to scan a book page by page resulting a scanned PDF document. Usually you start with the first (odd) page then you turn your book and scan the other (even) page. Or you may start in reverse order, it doesn't matter. You will continue the process until the desired book's pages are all scanned.

The result will be a PDF document where the odd pages are rotated well and the even pages are rotated upside down. Or it might be exactly inversely.

Depending on the PDF reader application you might use you might be able to rotate a page or not but reading a 400-pages document by rotating every other page is a pain in the ass. That is the moment when you decide to do something about it. The solution is to rotate the even pages in the same order like the odd pages.

How to rotate even odd scanned PDF pages in Linux

In Linux we have many tools available freely which helps us to do this job (that's the difference between Linux and Windows). We are going to use the pdftk tool. Depending on your Linux distro the pdftk may be already installed or not. If it's not then please search your Linux package manager for a package named "pdftk".

In Gentoo it is called "app-text/pdftk" so it can be installed like:


In Ubuntu/Debian it is called "pdftk" so it can be installed like:


There are hundreds Linux distro out there so please consult your Linux distro manual about how to install a package.

Anyway, once the pdftk is installed we just have to use it. If you want to learn more about its options then please check out its Linux manual.

To automate a bit the process a wrote a BASH script (pdf-rotate) that accepts some useful arguments (like input-output documents, start-end page, rotation angle for odd-even pages, etc) and simplifies the task making it as simple as shooting a fish in a barrel:

The script code

Usage example 1:

We want to rotate the input document "my-book.pdf" (which has 125 pages) such that the odd pages are rotated 180 degrees (because they are rotated upside down) and the even pages are rotated zero degrees (we don't want to touch them, they are OK as they are). By using my script mentioned above this task is accomplished as following:

Usage example 2:

We want to accomplish the same task like in the Example 1 above with the mention that only the pages within tge page 25-80 rage must be fixed, the others do no require any rotation. So we are going to rotate the start_page=25 to end_page=80 like in the Example 1 resulting a new document called my-book-25-80.pdf. By doing so we missed the pages within the 1-24 and 81-125 ranges. So the task becomes a bit more complicated:

  1. extract the pages within the 1-24 range unchanged (no rotation required)
  2. extract the pages within the 25-80 range rotated as necessary
  3. extract the pages within the 81-125 range unchanged (no rotation required)
  4. concatenate these 3 PDF files into a single PDF document

These steps are accomplished with only 4 commands at your Linux terminal:

How to rotate even odd scanned PDF pages in Windows

There is a PDFtk for Windows available freely. Just try to use the logic above with that program although I think there might be some limitations.

Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.

 
The following two tabs change content below.
How to rotate even odd scanned PDF pages

Eugen Mihailescu

Founder/programmer/one-man-show at Cubique Software
Always looking to learn more about *nix world, about the fundamental concepts of math, physics, electronics. I am also passionate about programming, database and systems administration. 16+ yrs experience in software development, designing enterprise systems, IT support and troubleshooting.
How to rotate even odd scanned PDF pages

Latest posts by Eugen Mihailescu (see all)

Tagged on: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: