Skip to content

Commit

Permalink
FIX: Cope with Matrix entry in field annotations (#2736)
Browse files Browse the repository at this point in the history
Closes #2731
  • Loading branch information
pubpub-zz authored Jul 19, 2024
1 parent fe33cf6 commit 4a41c53
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:/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 4a41c53

Please sign in to comment.