Skip to content

Commit

Permalink
BUG : cope with extra space
Browse files Browse the repository at this point in the history
  • Loading branch information
pubpub-zz committed Sep 5, 2023
1 parent 05f2a65 commit 0456cf7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ def _update_text_field(self, field: DictionaryObject) -> None:
# Extract font information
da = cast(str, field[AA.DA])
font_properties = da.replace("\n", " ").replace("\r", " ").split(" ")
font_properties = [x for x in font_properties if x != ""]
font_name = font_properties[font_properties.index("Tf") - 2]
font_height = float(font_properties[font_properties.index("Tf") - 1])
if font_height == 0:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1783,3 +1783,17 @@ def test_viewerpreferences():
assert reader.viewer_preferences is None
writer = PdfWriter(clone_from=reader)
assert writer.viewer_preferences is None


def test_extra_spaces_in_da_text(caplog):
writer = PdfWriter(clone_from=RESOURCE_ROOT / "form.pdf")
t = writer.pages[0]["/Annots"][0].get_object()["/DA"]
t = t.replace("/Helv", "/Helv ")
writer.pages[0]["/Annots"][0].get_object()[NameObject("/DA")] = TextStringObject(t)
writer.update_page_form_field_values(
writer.pages[0], {"foo": "abcd"}, auto_regenerate=False
)
t = writer.pages[0]["/Annots"][0].get_object()["/AP"]["/N"].get_data()
assert "Font dictionary for not found." not in caplog.text
assert b"/Helv" in t
assert b"(abcd)" in t

0 comments on commit 0456cf7

Please sign in to comment.