Skip to content

Instantly share code, notes, and snippets.

@jongyeol
Created October 6, 2010 04:59
Show Gist options
  • Save jongyeol/612853 to your computer and use it in GitHub Desktop.
Save jongyeol/612853 to your computer and use it in GitHub Desktop.
Rotate a pdf to landscape for Kindle
#!/usr/bin/python
# Rotate a pdf to landscape for Kindle
# http://gist.github.com/612853
# coded by jong10 <jong10@gmail.com>
# Usage (example)
# > python rotate-pdf.py input.pdf output.pdf
# supress deprecated warnings
import warnings
warnings.simplefilter('ignore', DeprecationWarning)
import sys
import pyPdf
if __name__ == '__main__':
if len(sys.argv) != 3:
print 'Usage: %s [input-pdf] [output-pdf]' % sys.argv[0]
exit(1)
o = pyPdf.PdfFileWriter()
i = pyPdf.PdfFileReader(file(sys.argv[1], "rb"));
for p in i.pages:
o.addPage(p.rotateCounterClockwise(90))
ostream = file(sys.argv[2], "wb")
o.write(ostream)
ostream.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment