Skip to content

Instantly share code, notes, and snippets.

Last active Jul 22, 2021
What would you like to do?
import textract
import PyPDF2
def extract_text_from_pdf(file):
'''Opens and reads in a PDF file from path'''
fileReader = PyPDF2.PdfFileReader(open(file,'rb'))
page_count = fileReader.getNumPages()
text = [fileReader.getPage(i).extractText() for i in range(page_count)]
return str(text).replace("\\n", "")
def extract_text_from_word(filepath):
'''Opens en reads in a .doc or .docx file from path'''
txt = textract.process(filepath).decode('utf-8')
return txt.replace('\n', ' ').replace('\t', ' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment