PDF-TOOLBOX
PDF-TOOLBOX copied to clipboard
Add pdfminer to requirements - and bug report.
Add pdfminer to requirements.
- In requirements.txt pdfminer isn't listed.
When running PDF-to-Text option I get
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'
@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, throughpip install pdfminer.six - Modify the text-to-speech function:-
Update the
convert_pdf_to_txtfunction to remove thecodecargument 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
let me know, if it works thanks