You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeError: TextConverter.__init__() got an unexpected keyword argument 'codec'
Full Error:
Traceback (most recent call last):
File "/home/user/Apps/PDF-TOOLBOX/pdf-toolbox.py", line 535, in<module>program()
File "/home/user/Apps/PDF-TOOLBOX/pdf-toolbox.py", line 526, in program
menu()
File "/home/user/Apps/PDF-TOOLBOX/pdf-toolbox.py", line 446, in menu
pdf2txt()
File "/home/user/Apps/PDF-TOOLBOX/pdf-toolbox.py", line 356, in pdf2txt
print(convert_pdf_to_txt(x))
^^^^^^^^^^^^^^^^^^^^^
File "/home/user/Apps/PDF-TOOLBOX/pdf-toolbox.py", line 334, in convert_pdf_to_txt
with TextConverter(rsrcmgr, retstr, codec=codec,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: TextConverter.__init__() got an unexpected keyword argument 'codec'
The text was updated successfully, but these errors were encountered:
@Theblackcat98 The error you're encountering with pdfminer is due to changes in the pdfminer.six library, where the codec argument is no longer accepted by the TextConverter class.
Try out these steps, and let me know, if it works
update the req.txt file with inclusion of latest version pdfminer.six, through pip install pdfminer.six
Modify the text-to-speech function:-
Update the convert_pdf_to_txt function to remove the codec argument from the TextConverter initialization.
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.pdfpage import PDFPage
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from io import StringIO
def convert_pdf_to_txt(path):
rsrcmgr = PDFResourceManager()
retstr = StringIO()
laparams = LAParams()
device = TextConverter(rsrcmgr, retstr, laparams=laparams)
fp = open(path, 'rb')
interpreter = PDFPageInterpreter(rsrcmgr, device)
for page in PDFPage.get_pages(fp):
interpreter.process_page(page)
text = retstr.getvalue()
fp.close()
device.close()
retstr.close()
return text
Add pdfminer to requirements.
When running PDF-to-Text option I get
Full Error:
The text was updated successfully, but these errors were encountered: