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

BUG: Line breaks are not generated due to incorrect calculation at the text leading #2890

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pypdf/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,8 @@ def process_operation(operator: bytes, operands: List[Any]) -> None:
elif operator == b"Tw":
space_scale = 1.0 + float(operands[0])
elif operator == b"TL":
TL = float(operands[0])
scale_x = math.sqrt(tm_matrix[0]**2 + tm_matrix[2]**2)
TL = float(operands[0]) * font_size * scale_x
elif operator == b"Tf":
if text != "":
output += text # .translate(cmap)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_text_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,11 @@ def test_space_position_calculation():
page = reader.pages[3]
extracted = page.extract_text()
assert "Shortly after the Geneva BOF session, the" in extracted


def test_text_leading_height_unit():
"""Tests for #2262"""
reader = PdfReader(RESOURCE_ROOT / "toy.pdf")
page = reader.pages[0]
extracted = page.extract_text()
assert "Something[cited]\n" in extracted
Loading