Created
July 24, 2019 18:52
-
-
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
This file contains hidden or 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
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