Skip to content

Commit

Permalink
ROB: Cope with missing Standard 14 fonts in fields (#2677)
Browse files Browse the repository at this point in the history
Closes #2670
Closes #2671
  • Loading branch information
pubpub-zz authored Jun 7, 2024
1 parent 44d08ae commit 3c9f449
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
cast,
)

from ._cmap import build_char_map_from_dict
from ._cmap import _default_fonts_space_width, build_char_map_from_dict
from ._doc_common import PdfDocCommon
from ._encryption import EncryptAlgorithm, Encryption
from ._page import PageObject
Expand Down Expand Up @@ -824,7 +824,8 @@ def _update_field_annotation(
).get_object(),
)
dr = dr.get("/Font", DictionaryObject()).get_object()
if font_name not in dr:
# _default_fonts_space_width keys is the list of Standard fonts
if font_name not in dr and font_name not in _default_fonts_space_width:
# ...or AcroForm dictionary
dr = cast(
Dict[Any, Any],
Expand Down
16 changes: 16 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2253,3 +2253,19 @@ def test_selfont():
assert (
b"Text_2" in writer.pages[0]["/Annots"][2].get_object()["/AP"]["/N"].get_data()
)


@pytest.mark.enable_socket()
def test_no_ressource_for_14_std_fonts(caplog):
"""Cf #2670"""
url = "https://github.com/py-pdf/pypdf/files/15405390/f1040.pdf"
name = "iss2670.pdf"
writer = PdfWriter(BytesIO(get_data_from_url(url, name=name)))
p = writer.pages[0]
for a in p["/Annots"]:
a = a.get_object()
if a["/FT"] == "/Tx":
writer.update_page_form_field_values(
p, {a["/T"]: "Brooks"}, auto_regenerate=False
)
assert "Font dictionary for /Helvetica not found." in caplog.text

0 comments on commit 3c9f449

Please sign in to comment.