Skip to content

Commit

Permalink
ROB: Discard /I in choice fields for compatibility with Acrobat (#2614)
Browse files Browse the repository at this point in the history
Closes #2611
  • Loading branch information
pubpub-zz committed May 1, 2024
1 parent 6819f86 commit b1b55e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pypdf/_writer.py
Expand Up @@ -987,6 +987,11 @@ def update_page_form_field_values(
or writer_parent_annot.get("/T", None) == field
):
continue
if (
writer_parent_annot.get("/FT", None) == "/Ch"
and "/I" in writer_parent_annot
):
del writer_parent_annot["/I"]
if flags:
writer_annot[NameObject(FA.Ff)] = NumberObject(flags)
if isinstance(value, list):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_writer.py
Expand Up @@ -2217,3 +2217,16 @@ def test_init_without_named_arg():
assert len(writer._objects) == nb
writer = PdfWriter(by)
assert len(writer._objects) == nb


@pytest.mark.enable_socket()
def test_i_in_choice_fields():
"""Cf #2611"""
url = "https://github.com/py-pdf/pypdf/files/15176321/FRA.F.6180.150.pdf"
name = "iss2611.pdf"
writer = PdfWriter(BytesIO(get_data_from_url(url, name=name)))
assert "/I" in writer.get_fields()["State"].indirect_reference.get_object()
writer.update_page_form_field_values(
writer.pages[0], {"State": "NY"}, auto_regenerate=False
)
assert "/I" not in writer.get_fields()["State"].indirect_reference.get_object()

0 comments on commit b1b55e6

Please sign in to comment.