I would like to extract text from PDF files. I could successfully install tesseract (it works in Terminal) and textract (following this instruction).
However, when I run the code, I got an error.
text = textract.process(
'/Users/Text/en.pdf',
method='tesseract',
language='eng',
)
Error is:
/usr/local/lib/python3.4/site-packages/textract-1.4.0-py3.4.egg/textract/parsers/pdf_parser.py in extract_tesseract(self, filename, **kwargs)
62 page_content = TesseractParser().extract(page_path, **kwargs)
63 contents.append(page_content)
---> 64 return ''.join(contents)
65 finally:
66 shutil.rmtree(temp_dir)
TypeError: sequence item 0: expected str instance, bytes found
I tried several modifications, but they never work and I got the same error.
return b''.join(contents)
- Insert
contents = [str(item) for item in contents]
beforereturn
- Insert
contents = [item.decode("utf-8") for item in contents]
beforereturn