How to Rotate a Multi Page PDF in Ubuntu Linux

So you have a PDF file that might be one or more pages, but you want to rotate the pages? Use these simple steps from your Ubuntu Linux command line terminal:

  1. Run sudo apt-get install python-pypdf (you need this to modify PDFs with Python)
  2. Create a text document to contain this python code:
    #!/usr/bin/env python
    import sys
    from pyPdf import PdfFileWriter, PdfFileReader
    input = PdfFileReader(sys.stdin)
    output = PdfFileWriter()
    for i in range(0,input.getNumPages()):
        output.addPage(input.getPage(i).rotateClockwise(90))
        output.write(sys.stdout)

    You can change 90 to -90 to rotate the other direction (left instead of right).

  3. Save & Close the file as rotatepdf.py
  4. Run chmod 755 rotatepdf.py to make it executable
  5. Run ./rotatepdf.py < input.pdf > output.pdf

Input.pdf is your original PDF file that is not rotated. Output.pdf is the PDF after rotation is applied (do not use the same filename for both).