Skip to content

Commit 5400f5a

Browse files
committed
BUG: Missing spaces in extract_text() method (#1328)
1 parent d974d5c commit 5400f5a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pypdf/_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ def process_operation(operator: bytes, operands: List[Any]) -> None:
19891989
if isinstance(op, (str, bytes)):
19901990
process_operation(b"Tj", [op])
19911991
if isinstance(op, (int, float, NumberObject, FloatObject)) and (
1992-
(abs(float(op)) >= _space_width)
1992+
(math.ceil(abs(float(op))) >= _space_width)
19931993
and (len(text) > 0)
19941994
and (text[-1] != " ")
19951995
):

tests/test_text_extraction.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,20 @@ def test_layout_mode_warnings(mock_logger_warning):
189189
mock_logger_warning.assert_called_with(
190190
"Argument visitor_text is ignored in layout mode", "pypdf._page"
191191
)
192+
193+
194+
@pytest.mark.enable_socket()
195+
def test_space_with_one_unit_smaller_than_font_width():
196+
"""Tests for #1328"""
197+
url = "https://github.com/py-pdf/PyPDF2/files/9498481/0004.pdf"
198+
name = "iss1328.pdf"
199+
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
200+
page = reader.pages[0]
201+
extracted = page.extract_text().split("Description:")[1].split("8/11/22")[0].strip()
202+
assert """Reporting crude oil leak.
203+
Leak was isolated to well
204+
pad. Segment of line was
205+
immediately isolated, now
206+
estimated at 5 barrels of oil
207+
spilt. Root cause still
208+
unknown at this time.""" == extracted

0 commit comments

Comments
 (0)