Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

from .pdftypes import PDFObjectNotFound ImportError: cannot import name 'PDFObjectNotFound'

Tags:

python-3.x

I am trying to convert PDF to TEXT. But I have problem in PDFPage class. I have searched about it. But I didn't get anything and it gives me following error. I have also installed pdfminer.six for python 3.5 but still I didn't get any solution. Please help.

Code :

from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
import os
import sys, getopt

#converts pdf, returns its text content as a string


 def extract_text_from_pdf(pdf_path):
    with open(pdf_path, 'rb') as fh:
        for page in PDFPage.get_pages(fh, 
                                      caching=True,
                                      check_extractable=True):
            resource_manager = PDFResourceManager()
            fake_file_handle = io.StringIO()
            converter = TextConverter(resource_manager, fake_file_handle, codec='utf-8', laparams=LAParams())
            page_interpreter = PDFPageInterpreter(resource_manager, converter)
            page_interpreter.process_page(page)

            text = fake_file_handle.getvalue()
            yield text

            # close open handles
            converter.close()
            fake_file_handle.close()

Error :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/system/anaconda3/lib/python3.6/site-packages/pdfminer/pdfpage.py", line 5, in <module>
    from .pdftypes import PDFObjectNotFound
ImportError: cannot import name 'PDFObjectNotFound'
like image 312
Heena Avatar asked Oct 16 '25 03:10

Heena


1 Answers

Uninstall pdfminer3k (if you have it installed)

$ pip uninstall pdfminer3k

and install pdfminer.six using the command below.

$ python -m pip install pdfminer.six
like image 189
SuperNova Avatar answered Oct 17 '25 17:10

SuperNova



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!