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

KeyError raised when pdf image object has no bounding box information #72

Closed
meldonization opened this issue Aug 2, 2018 · 3 comments
Closed

Comments

@meldonization
Copy link
Contributor

image object

{
    'srcsize': (Decimal('210'), Decimal('198')), 
    'height': Decimal('148.600'),
    'object_type': 'image', 
    'bits': Decimal('8'), 
    'width': Decimal('157.550')
}

Error Msg.

a = pdf_page.crop((0, table.bbox[1], page_width, table.bbox[3]))
a.images
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pdfplumber/container.py", line 27, in images
    return self.objects.get("image", [])
  File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pdfplumber/page.py", line 174, in objects
    self.bbox)
  File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pdfplumber/utils.py", line 317, in crop_to_bbox
    for k,v in objs.items())
  File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pdfplumber/utils.py", line 317, in <genexpr>
    for k,v in objs.items())
  File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pdfplumber/utils.py", line 321, in crop_to_bbox
    scores = n_points_intersecting_bbox(objs, bbox)
  File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pdfplumber/utils.py", line 281, in n_points_intersecting_bbox
    return list(scores)
  File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pdfplumber/utils.py", line 280, in <genexpr>
    scores = (obj_inside_bbox_score(obj, bbox) for obj in objs)
  File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pdfplumber/utils.py", line 230, in obj_inside_bbox_score
    (obj["x0"], obj["top"]),
KeyError: 'x0'
@jsvine
Copy link
Owner

jsvine commented Aug 3, 2018

Thanks for flagging this, @meldonization. Do you have an PDF exhibiting this behavior that you can share?

@meldonization
Copy link
Contributor Author

Here it is. Checkout the images within the first page.

image_without_bbox_info.pdf

@meldonization meldonization changed the title KeyError raised when pdf image object has no bounding box information KeyError raised when pdf image object has no bounding box information #bug Nov 27, 2018
@meldonization meldonization changed the title KeyError raised when pdf image object has no bounding box information #bug KeyError raised when pdf image object has no bounding box information Nov 27, 2018
@samkit-jain
Copy link
Collaborator

Reviving an old issue. @meldonization Is this an issue anymore? As of 2 August 2018, pdfplumber version was 0.5.9 and the recent one is 0.5.24 and I suspect the issue may have been resolved. If not, could you please tell how to get the value of table that I can put in the crop() method and test?

@jsvine jsvine closed this as completed Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants