I am trying to extract the text in doem PDF files using Textract. However, when I print the text in the end of the code, it just prints out a lot of empty spaces. Can anyone point me in direction of what is going on? (text is not = "", by the way)
import os
import codecs
import PyPDF2
import textract
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
for filename in os.listdir('Harbour PDF'):
if '.DS_Store' == filename:
continue
filename = 'Harbour PDF/' + filename
print(filename)
pdfFileObj = open(filename,'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
num_pages = pdfReader.numPages
count = 0
text = ""
while count < num_pages:
pageObj = pdfReader.getPage(count)
count +=1
text += pageObj.extractText()
if text != "":
text = text
else:
text = textract.process(pdfFileObj, method='tesseract', language='eng')
print(text)