LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Rotate every second page of a pdf-document (https://www.linuxquestions.org/questions/linux-software-2/rotate-every-second-page-of-a-pdf-document-4175578453/)

knuno 04-27-2016 06:33 AM

Rotate every second page of a pdf-document
 
I have several thousand 2-page PDF-files where the second page is rotated 180 degrees relative to the first. I would like to rotate the upside down page so that I have a nice straight forward document. I am able to do this using several Imagemagic commands per document:

convert -density 300x300 original.pdf[0] scra01.pdf
convert -density 300x300 -rotate 180 original.pdf[1] scra02.pdf
convert -density 300x300 scra01.pdf scra02.pdf new_complete.pdf

But can I do this in one command?

Knut

HMW 04-27-2016 07:33 AM

Hi!

If it is the second document always, you can use a loop and a counter, and only change those documents (pdfs) who are even numbered (based on the counter).

In pseudo code:
Code:

counter = 0
for doc in directory; do
    counter++
    if counter is even; then
        rotate doc
    else
        continue
    fi
done

Best regards,
HMW

Michael Uplawski 04-27-2016 07:39 AM

@HMW: The OP wants to rotate *pages* in a document, not documents.

PDFTK has options to rotate single pages.
From the man-page:
Quote:

rotate [<page ranges>]
Takes a single input PDF and rotates just the specified pages. All other pages remain unchanged.
The page order remains unchaged. Specify the pages to rotate using the same notation as you would
with cat, except you omit the pages that you aren't rotating:

[<begin page number>[-<end page number>[<qualifier>]]][<page rotation>]

The qualifier can be even or odd, and the page rotation can be north, south, east, west, left,
right, or down.

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.

The given order of the pages doesn't change the page order in the output.
As regards graphical user-interfaces, PDF Mod lets you rotate single pages. I ignore if pdfchain (the GUI for pdftk) offers the option. You should opt for pdftk and automate the process for all your documents in a loop.

Edit: Okay, PDF Chain is cool, too. It lets you work on several documents simultaneously, select pages and manipulate only selected pages. Rotation is easy.

keefaz 04-27-2016 07:47 AM

PDFtk looks fine, I would rather avoid convert pdf to image (makes text non searchable, non selectable etc)

HMW 04-27-2016 10:01 AM

Quote:

Originally Posted by Michael Uplawski (Post 5537263)
@HMW: The OP wants to rotate *pages* in a document, not documents.

Ah! Thanks for clarifying, my bad!

HMW

Michael Uplawski 04-27-2016 12:08 PM

Quote:

Originally Posted by keefaz (Post 5537265)
PDFtk looks fine, I would rather avoid convert pdf to image (makes text non searchable, non selectable etc)

There are reasons. See my blog.

knuno 04-28-2016 10:00 AM

PDFtk or Imagemagic
 
Thank you for your answers and recomendation of PDFtk. I already looked into it and I'm quite sure it will do the job. But since Fedora 23, with KDE, do not have this in its standard repositories I found it a bit more of a hassle to install it. Besides I'm also curious as to how to work with multi page documents (PDF or TIFF) in Imagemagic.

Knut


All times are GMT -5. The time now is 03:44 PM.