I passed the file object but still getting parse error with slate3k

1k Views Asked by At

I am trying to read the text data of pdf file using "slate3k" . It seems fine to me. But I am getting parse error

I have been using "python3.7" .

import slate3k

with open("/home/am-it/Desktop/PythonLearning/pdf_practice/invoice-1.pdf","rb")as file:
    doc = slate3k.PDF(file)
    print(doc)

The Output of above code should be text from pdf. but the actual output is

 "Traceback (most recent call last):
  File "/home/am-it/Desktop/PythonLearning/pdf_practice/invoslate.py", line 4, in <module>
    doc = slate3k.PDF(file)
  File "/home/administrator/.local/lib/python3.7/site-packages/slate3k/classes.py", line 59, in __init__
    self.doc = PDFDocument()
TypeError: __init__() missing 1 required positional argument: 'parser'" 

I have passed the proper file object but still getting error. So please enlighten me

2

There are 2 best solutions below

1
On

Dude, in this part of the code: with open("/home/am-it/Desktop/PythonLearning/pdf_practice/invoice-1.pdf","rb")as file:

you have to write the name of the file plus the extension and not the path. So, try this: with open("invoice-1.pdf","rb")as file:

0
On

Mine works well with single quotes and with print not indented

import slate3k as slt
with open('pdfPythonTest.pdf','rb') as f:
    extracted_text=slt.PDF(f)
print(extracted_text)

Hope this helps!