Skip to content

Commit

Permalink
Restore "text" attr to .textboxhorizontal/etc.
Browse files Browse the repository at this point in the history
Fix regression introduced in 9587cc7 / v0.6.2.
  • Loading branch information
jsvine committed Nov 22, 2022
1 parent e63a038 commit 8a0c126
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pdfplumber/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
LTLine,
LTPage,
LTRect,
LTTextContainer,
)
from pdfminer.pdfinterp import PDFPageInterpreter
from pdfminer.pdfpage import PDFPage
Expand Down Expand Up @@ -211,8 +212,10 @@ def process_attr(item: Tuple[str, Any]) -> Optional[Tuple[str, Any]]:
attr["object_type"] = kind
attr["page_number"] = self.page_number

if isinstance(obj, LTChar):
if isinstance(obj, (LTChar, LTTextContainer)):
attr["text"] = obj.get_text()

if isinstance(obj, LTChar):
gs = obj.graphicstate
attr["stroking_color"] = gs.scolor
attr["non_stroking_color"] = gs.ncolor
Expand Down
4 changes: 4 additions & 0 deletions tests/test_laparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def test_with_laparams(self):
page = pdf.pages[0]
assert len(page.textboxhorizontals) == 27
assert len(page.textlinehorizontals) == 79
assert "text" in page.textboxhorizontals[0]
assert "text" in page.textlinehorizontals[0]
assert len(page.chars) == 4408
assert "anno" not in page.objects.keys()

Expand All @@ -38,6 +40,8 @@ def test_vertical_texts(self):
assert len(page.textboxhorizontals) == 74
assert len(page.textlineverticals) == 11
assert len(page.textboxverticals) == 6
assert "text" in page.textboxverticals[0]
assert "text" in page.textlineverticals[0]

def test_issue_383(self):
with pdfplumber.open(self.path, laparams={}) as pdf:
Expand Down

0 comments on commit 8a0c126

Please sign in to comment.