Skip to content

Conversation

@LudovA
Copy link
Contributor

@LudovA LudovA commented Jan 14, 2026

Fixes crash when extracting text from PDFs with fonts missing bounding boxes.

Problem

pypdf crashed with KeyError: 'bbox' when encountering fonts without a /FontBBox entry in their descriptor. This commonly occurs with PDFs exported from Google Docs containing emoji characters.

Solution

Modified _parse_font_descriptor() in _font.py to check if the bbox key exists before accessing it.

Changes

  • Handle missing /FontBBox gracefully in font descriptor parsing
  • Added regression test with Google Docs-exported PDF containing emoji
  • Test verifies text extraction completes without KeyError

Closes #3599

@LudovA LudovA marked this pull request as draft January 14, 2026 15:04
@LudovA LudovA changed the title Fix text extraction crash when fonts lack bounding box ROB: Handle missing font bounding boxes gracefully Jan 14, 2026
@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.35%. Comparing base (affe8ed) to head (d6ef2bc).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3600   +/-   ##
=======================================
  Coverage   97.35%   97.35%           
=======================================
  Files          55       55           
  Lines        9815     9816    +1     
  Branches     1791     1792    +1     
=======================================
+ Hits         9555     9556    +1     
  Misses        153      153           
  Partials      107      107           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Some PDFs (e.g., Google Docs exports with emojis) have fonts without
valid bounding boxes in their font descriptors. pypdf now gracefully
uses the default bbox when /FontBBox is missing instead of crashing
with KeyError: 'bbox'.
Adds test_extract_text_with_missing_font_bbox() which tests that
PDFs with fonts lacking valid bounding boxes don't cause KeyError.
Includes the missing_font_bbox.pdf test file from Google Docs that
originally triggered the issue.
@LudovA LudovA force-pushed the fix-missing-font-bbox branch from 218bf2a to 5acf8a7 Compare January 14, 2026 15:13
@LudovA LudovA marked this pull request as ready for review January 14, 2026 15:15
Copy link
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I have left some comments, which hopefully should be rather straightforward to solve.

@LudovA LudovA requested a review from stefan6419846 January 14, 2026 16:13
@stefan6419846 stefan6419846 merged commit 26fd638 into py-pdf:main Jan 14, 2026
18 checks passed
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

Successfully merging this pull request may close these issues.

Handle missing 'bbox' in font descriptor gracefully

2 participants