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

Prevent line breaks, deliver reading order. #3878

Merged
merged 1 commit into from
Sep 23, 2024
Merged

Conversation

JorjMcKie
Copy link
Collaborator

Refactor plain text and "words" extraction when option sort=True is used:
We previously simply sorted output by ascending bottom and left coordinate. This change collects words (and respectively text portions) that are approximately on the same line. Apart from extremely malformed pages, words and text are returned in "natural" reading sequence.

This change also suppresses line breaks generated by MuPDF just because of large horizontal distances, as it e.g. often happens between table cell content of the same row.

This change does not alter the user's API and is only activated if Page.get_text(sort=True) or Page.get_text("words", sort=True) is used.

@JorjMcKie
Copy link
Collaborator Author

Have added test data and script.

src/utils.py Outdated Show resolved Hide resolved
src/utils.py Outdated Show resolved Hide resolved
src/utils.py Outdated Show resolved Hide resolved
src/utils.py Show resolved Hide resolved
src/utils.py Show resolved Hide resolved
Refactor plain text and "words" extraction with sort=True:
We previously simply sorted the output by ascending bottom and left coordinate.
This change collects words  (and respectively text) that are approximately on the same line.
Apart from extremely malformed pages, words and respectively text is returned in "natural" reading sequence.

This change also suppresses line breaks generated by MuPDF just because of large horizontal distances (as it e.g. often happens between  table cell content of the same row.
@JorjMcKie
Copy link
Collaborator Author

Now verified that it works for MuPDF v1.24.9 ...

@JorjMcKie JorjMcKie merged commit 75a060d into main Sep 23, 2024
2 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 23, 2024
@JorjMcKie JorjMcKie deleted the prevent-linebreaks branch September 23, 2024 16:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants