From b1b55e67e1acb9f96268bbfee9b39da33f52e983 Mon Sep 17 00:00:00 2001 From: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com> Date: Wed, 1 May 2024 13:57:42 +0200 Subject: [PATCH] ROB: Discard /I in choice fields for compatibility with Acrobat (#2614) Closes #2611 --- pypdf/_writer.py | 5 +++++ tests/test_writer.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/pypdf/_writer.py b/pypdf/_writer.py index b90dd4494..6d42cdfaa 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -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): diff --git a/tests/test_writer.py b/tests/test_writer.py index 89b791211..3460a3a48 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -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()