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

ROB: cope with missing Standard 14 fonts in fields #2677

Merged
merged 3 commits into from
Jun 7, 2024
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
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
Loading