Fix bug w/ use_text_flow=True extractions (#1279)

... related to flows where text bounces between lines.

h/t @samuelbradshaw
This commit is contained in:
Jeremy Singer-Vine
2025-03-27 22:44:25 -04:00
parent f2ad9423fa
commit e15ed98a26
3 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -587,7 +587,7 @@ class WordExtractor:
(cx < ax)
or (cx > bx + x)
# Interline test
or (cy > ay + y)
or abs(cy - ay) > y
)
def iter_chars_to_words(
Binary file not shown.
+13
View File
@@ -336,6 +336,19 @@ class Test(unittest.TestCase):
re.search("2015 RICE PAYMENT 26406576 0 1207631 Cr", not_using_flow) is None
)
def test_text_flow_words_mixed_lines(self):
path = os.path.join(HERE, "pdfs/issue-1279-example.pdf")
with pdfplumber.open(path) as pdf:
p0 = pdf.pages[0]
words = p0.extract_words(use_text_flow=True)
texts = set(w["text"] for w in words)
assert "claim" in texts
assert "lence" in texts
assert "claimlence" not in texts
def test_extract_text(self):
text = self.pdf.pages[0].extract_text()
goal_lines = [