Skip to content

Instantly share code, notes, and snippets.

@haider11234
Last active January 11, 2021 07:47
Show Gist options
  • Save haider11234/fedde530c3860e92c7c427d18bd20fe7 to your computer and use it in GitHub Desktop.
Save haider11234/fedde530c3860e92c7c427d18bd20fe7 to your computer and use it in GitHub Desktop.
# importing the required modules
from PyPDF2 import PdfFileReader, PdfFileWrite
def PDFrotate(File_Name, output, rotation):
pdfFile = open(File_Name, 'rb')
pdfReader = PdfFileReader(pdfFile)
# creating a pdf writer object for new pdf
pdfWriter = PdfFileWriter()
for page in range(pdfReader.numPages):
pageObj = pdfReader.getPage(page)
pageObj.rotateClockwise(rotation)
# adding rotated page object to pdf writer
pdfWriter.addPage(pageObj)
# new pdf file object
output = open(File_Name, 'wb')
# writing rotated pages to new file
pdfWriter.write(output)
# closing the original pdf file object
pdfFile.close()
# closing the new pdf file object
output.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment