Skip to content

Commit

Permalink
FIX: Cope with Matrix entry in field annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
pubpub-zz committed Jul 2, 2024
1 parent de07cbc commit 6053663
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,10 @@ def _update_field_annotation(
"/Length": 0,
}
)
if AA.AP in anno:
for k, v in cast(DictionaryObject, anno[AA.AP]).get("/N", {}).items():
if k not in {"/BBox", "/Length", "/Subtype", "/Type", "/Filter"}:
dct[k] = v

# Update Resources with font information if necessary
if font_res is not None:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2286,3 +2286,17 @@ def test_field_box_upside_down():
box = writer.pages[0]["/Annots"][13].get_object()["/AP"]["/N"]["/BBox"]
assert box[2] > 0
assert box[3] > 0


@pytest.mark.enable_socket()
def test_matrix_entry_in_field_annots():
"""Cf #2731"""
url = "https://github.com/user-attachments/files/16036514/template.pdf"
name = "iss2731.pdf"
writer = PdfWriter(BytesIO(get_data_from_url(url, name=name)))
writer.update_page_form_field_values(
writer.pages[0],
{"Stellenbezeichnung_1": "some filled in text"},
auto_regenerate=False,
)
assert "/Matrix" in writer.pages[0]["/Annots"][5].get_object()["/AP"]["/N"]

0 comments on commit 6053663

Please sign in to comment.