I scanned a bunch of papers into a pdf but they seem to all be rotated, is there a way to rotate the pages with python?
I did see the question in Python - Batch rotate pdf with PyPDF2 but am looking for a more generic solution.
I scanned a bunch of papers into a pdf but they seem to all be rotated, is there a way to rotate the pages with python?
I did see the question in Python - Batch rotate pdf with PyPDF2 but am looking for a more generic solution.
The best resource for PyPDF4 documentation at the time of this writing is PyPDF4's sample code - https://github.com/claird/PyPDF4/blob/master/samplecode/basic_features.py
Looking at that one can write a simple script to do this:
# pdf_rotate_every_page.py
from PyPDF4 import PdfFileReader, PdfFileWriter
from sys import argv, path, stderr
from os.path import abspath, basename, dirname, join
USAGE = "Rotate every page in a PDF. Call script with single pdf file as input argument"
def main():
output_writer = PdfFileWriter()
if len(argv) < 2:
print(USAGE)
exit(1)
else:
inputpath = argv[1].strip()
filename = basename(inputpath)[:-4]
if len(argv) > 2:
output = argv[2].strip()
with open(inputpath, "rb") as inputf:
pdfOne = PdfFileReader(inputf)
numPages = pdfOne.numPages
for i in list(range(0, numPages)):
page = pdfOne.getPage(i).rotateClockwise(180)
output_writer.addPage(page)
with open(filename + "_rotated.pdf", "wb") as outfile:
output_writer.write(outfile)
if __name__ == "__main__":
main()