Fix bug in dedup_chars() in which ._objects was accessed before assignment

Fixes #293
This commit is contained in:
Samkit Jain
2020-10-20 17:02:07 +05:30
parent 04fd56ac40
commit b132d45db5
3 changed files with 8 additions and 1 deletions
+1 -1
View File
@@ -270,7 +270,7 @@ class Page(Container):
and positioning (within `tolerance`) as other characters on the page.
"""
p = FilteredPage(self, True)
p._objects = dict((kind, objs) for kind, objs in self._objects.items())
p._objects = dict((kind, objs) for kind, objs in self.objects.items())
p._objects["char"] = utils.dedupe_chars(self.chars, **kwargs)
return p
Binary file not shown.
+7
View File
@@ -67,3 +67,10 @@ class Test(unittest.TestCase):
assert last_line_without_drop == '微微软软 培培训训课课程程:: 名名模模意意义义一一些些有有意意义义一一些些'
assert last_line_with_drop == '微软 培训课程: 名模意义一些有意义一些'
def test_extract_text2(self):
path = os.path.join(HERE, "pdfs/issue-71-duplicate-chars-2.pdf")
pdf = pdfplumber.open(path)
page = pdf.pages[0]
assert page.dedupe_chars().extract_text(y_tolerance=6).splitlines()[4] == "UE 8. Circulation - Métabolismes"