Skip to content

BUG: Use current text matrix for visitor_text - #4062

Merged
stefan6419846 merged 5 commits into
py-pdf:mainfrom
r-kamei:fix-2932-visitor-text-matrix
Sep 10, 2026
Merged

stefan6419846 merged 5 commits into
py-pdf:mainfrom
r-kamei:fix-2932-visitor-text-matrix

Conversation

@r-kamei

@r-kamei r-kamei commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix #2932.

visitor_text() could receive a stale text matrix when a new text
fragment begins with a synthesized leading space.

Tests

  • Added minimal reproducer PDF: visitor_text_position.pdf
  • Added regression test:
    test_visitor_text_uses_current_text_matrix

Fails before the fix, passes after the fix.

AI Usage

Development assistance: Microsoft Copilot (GPT-5).

@r-kamei

r-kamei commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

I noticed that the failing CI job is tests/test_reader.py::test_read_form_416.
That test downloads a PDF from the FDA website via get_data_from_url() and fails while constructing PdfReader
with:

PdfStreamError: Stream has ended unexpectedly

The failure appears to be outside the code path modified by this PR, which only affects visitor_text() text-matrix handling.

@stefan6419846

Copy link
Copy Markdown
Collaborator

Regarding #4062 (comment): In the past, this was a temporary flakiness of CI (like with some other files). As it relied on external URLs and thus can hopefully be made more reliable, I am currently changing this to use a local copy. After this, CI should hopefully pass again.

Comment thread tests/test_page.py Resolved
@codecov

codecov Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.11%. Comparing base (d80ccfc) to head (2c13aa0).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4062   +/-   ##
=======================================
  Coverage   98.10%   98.11%           
=======================================
  Files          59       59           
  Lines       11480    11476    -4     
  Branches     2148     2147    -1     
=======================================
- Hits        11263    11260    -3     
  Misses        122      122           
+ Partials       95       94    -1     

☔ View full report in Codecov by Harness.
📢 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.

@r-kamei

r-kamei commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

The remaining failure is a timeout in test_flatedecode__decode_png_prediction__speed, which appears unrelated to the changes in this PR.

Comment thread tests/test_text_extraction.py Resolved
@stefan6419846
stefan6419846 merged commit 735d284 into py-pdf:main Sep 10, 2026
20 checks passed
@r-kamei
r-kamei deleted the fix-2932-visitor-text-matrix branch September 10, 2026 23:48
stefan6419846 added a commit that referenced this pull request Sep 11, 2026
## What's new

### Security (SEC)
- Further restrict FlateDecode recovery (#4073) by @stefan6419846
- Limit entry count for TrueType and Type1 font `/Widths` (#4072) by @stefan6419846
- Limit allowed length of tokens in parse_bfchar (#4071) by @stefan6419846

### Bug Fixes (BUG)
- Use current text matrix for visitor_text (#4062) by @r-kamei
- Repeat the letter for /S /A and /S /a page labels past Z (#4065) by @youdie006
- Use font color for FreeText default appearance (#4051) by @Yuki9814

### Robustness (ROB)
- Fix compatibility with fonttools < 4.58.0 (#4050, #4059) by @MeggyCal and @stefan6419846

### Documentation (DOC)
- Use combined matrix in visitor examples (#4066) by @r-kamei

[Full Changelog](6.18.0...6.18.1)
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.

'extract_text' text matrix seems to be sometimes broken with v5.1.0

3 participants