Используя следующий код:
import PyPDF2
pdf_file = open('1.pdf', 'rb')
read_pdf = PyPDF2.PdfFileReader(pdf_file)
number_of_pages = read_pdf.getNumPages()
page = read_pdf.getPage(0)
page_content = page.extractText()
file = open("file.txt", "w", encoding="utf-8")
file.write(page_content)
file.close()
Пытаюсь прочитать текст из вот этого pdf файла.
Но вместо текста получаю следующую ошибку:
PdfReadWarning: Xref table not zero-indexed. ID numbers for objects will be corrected. [pdf.py:1736]
Traceback (most recent call last):
File "main.py", line 156, in <module>
number_of_pages = read_pdf.getNumPages()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\PyPDF2\pdf.py", line 1155, in getNumPages
self._flatten()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\PyPDF2\pdf.py", line 1505, in _flatten
catalog = self.trailer["/Root"].getObject()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\PyPDF2\generic.py", line 516, in __getitem__
return dict.__getitem__(self, key).getObject()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\PyPDF2\generic.py", line 178, in getObject
return self.pdf.getObject(self).getObject()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\PyPDF2\pdf.py", line 1604, in getObject
% (indirectReference.idnum, indirectReference.generation, idnum, generation))
PyPDF2.utils.PdfReadError: Expected object ID (5 0) does not match actual (4 0); xref table not zero-indexed.
Что я сделал не так? Как можно исправить данную проблему?