Первый вариант: PyPDF2
Сначала запустите его в cmd для установки PyPDF2: (может работать лучше, чем PyPDF3, который вы уже пробовали)
pip install PyPDF2
Затем дляИзвлеките текст из файла PDF, используя следующий код:
# importing required modules
import PyPDF2
# creating a pdf file object
pdfFileObj = open('example.pdf', 'rb')
# creating a pdf reader object
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
# printing number of pages in pdf file
print(pdfReader.numPages)
# creating a page object
pageObj = pdfReader.getPage(0)
# extracting text from page
print(pageObj.extractText())
# closing the pdf file object
pdfFileObj.close()
2-й вариант: Textract
Запустите это в cmd для установки textract
pip install textract
Затем, чтобы прочитать PDF, используйте следующий код:
import textract
text = textract.process('path/to/pdf/file', method='pdfminer')
Удачи!