Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save manojmohangit/dda97110362f156ad342580e70fe4121 to your computer and use it in GitHub Desktop.
Save manojmohangit/dda97110362f156ad342580e70fe4121 to your computer and use it in GitHub Desktop.
Check pdf file pages are rotated or not in a directory in Python
import PyPDF2
import os
#list all the files in the directory
files = os.listdir("pdffile")
for file in files:
#check if the file is pdf, if not skip the file
if ".pdf" not in file:
continue
#open the pdf file
pdfFileObj = open('pdffile/'+file, 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
# get number of pages in pdf file
totalPages = pdfReader.numPages
#loop through each page in the pdf file`
for i in range(1,totalPages):
#check if file is rotated at any angle, if yes, print the information in the file
if(pdfReader.getPage(i).get('/Rotate') != None and pdfReader.getPage(i).get('/Rotate') != 0):
print("FileName: "+file+" Page: "+str(i)+" "+"Angle: "+str(pdfReader.getPage(i).get('/Rotate')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment