1import PyPDF2 # Importing required modules
2pdfFileObj = open('example.pdf', 'rb') # creating a pdf file object
3pdfReader = PyPDF2.PdfFileReader(pdfFileObj) # creating a pdf reader object
4print(pdfReader.numPages) # printing number of pages in pdf file
5pageObj = pdfReader.getPage(0) # creating a page object
6print(pageObj.extractText()) # extracting text from page
7pdfFileObj.close() # closing the pdf file object