Last active
January 11, 2021 08:09
-
-
Save haider11234/b679de9942ef68f80a35967bf8ca7335 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# importing the required modules | |
from PyPDF2 import PdfFileReader, PdfFileWriter | |
def PDFrotate(Filename, output_name, rotation): | |
pdfFile = open(Filename, 'rb') | |
pdfReader = PdfFileReader(pdfFile) | |
pdfWriter = PdfFileWriter() | |
# rotating each page | |
for page in range(pdfReader.numPages): | |
# creating rotated page object | |
pageObj = pdfReader.getPage(page) | |
pageObj.rotateClockwise(rotation) | |
# adding rotated page object to pdf writer | |
pdfWriter.addPage(pageObj) | |
# new pdf file object | |
output = open(output_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() | |
PDFrotate("sample.pdf","rotate.pdf",270) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment