MAINT: Move code from _page.py to _text_extraction#3343
Merged
Conversation
76ca472 to
0214f87
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3343 +/- ##
=======================================
Coverage 96.73% 96.73%
=======================================
Files 53 54 +1
Lines 9060 9069 +9
Branches 1676 1676
=======================================
+ Hits 8764 8773 +9
Misses 177 177
Partials 119 119 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR moves code related to PDF text extraction from _page.py to a dedicated file in _text_extraction to improve maintainability and reduce merge conflicts. Key changes include:
- Moving the implementations of _get_actual_font_widths and _handle_tj into a new TextExtraction class.
- Adding a license preamble and creating a new file (pypdf/_text_extraction/_text_extractor.py) to house the extracted methods.
- Updating _page.py to remove duplicate logic and use the new TextExtraction instance.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pypdf/_text_extraction/_text_extractor.py | New file with the TextExtraction class and moved text extraction logic. |
| pypdf/_page.py | Removed duplicate extraction functions and updated calls to use the new TextExtraction class. |
stefan6419846
approved these changes
Jul 1, 2025
Collaborator
stefan6419846
left a comment
There was a problem hiding this comment.
Just did a quick check myself and the diff looks correct.
larsga
pushed a commit
to larsga/pypdf
that referenced
this pull request
Jul 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The goal of this PR is to increase maintainabilty by reducing the size of __page.py. This helps, because:
It also prepares for a big more complex refactoring (see #3339 )
For the Reviewer
This PR is almost only copy-paste (moving the location of the code, but no additions/changes):
_get_actual_font_widthsand_handle_tjwere only moved