Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdplumber return empty string on importerror #481

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/invoice2data/input/pdfplumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def to_text(path):
try:
import pdfplumber
except ImportError:
logger.debug("Cannot import pdfplumber")
logger.error("Cannot import pdfplumber")
raise ImportError("Cannot import pdfplumber")

raw_text = ""
raw_text = raw_text.encode(encoding='UTF-8')
Expand Down
6 changes: 5 additions & 1 deletion src/invoice2data/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ def extract_data(invoicefile, templates=None, input_module=None):
else:
input_module = pdftotext

extracted_str = input_module.to_text(invoicefile)
try:
extracted_str = input_module.to_text(invoicefile)
except Exception as e:
logger.error("Error has occured %s", e)
return False
if not isinstance(extracted_str, str) or not extracted_str.strip():
logger.error("Failed to extract text from %s using %s", invoicefile, input_module.__name__)
return False
Expand Down
Loading