Last active
August 29, 2024 13:37
-
-
Save jb0hn/760447d7737555793efe48fb4192802c to your computer and use it in GitHub Desktop.
Rotate PDF file with PyPDF2
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
#!/usr/bin/env python3 | |
import PyPDF2 | |
pdfIn = open('original.pdf', 'rb') # exchange the 'original.pdf' with a name of your file | |
pdfReader = PyPDF2.PdfFileReader(pdfIn) | |
pdfWriter = PyPDF2.PdfFileWriter() | |
for pageNum in range(pdfReader.numPages): | |
page = pdfReader.getPage(pageNum) | |
page.rotateClockwise(90) | |
pdfWriter.addPage(page) | |
pdfOut = open('rotated.pdf', 'wb') | |
pdfWriter.write(pdfOut) | |
pdfOut.close() | |
pdfIn.close() |
asafdaman
commented
Aug 29, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment