Skip to content

Commit 4a41c53

Browse files
authored
FIX: Cope with Matrix entry in field annotations (#2736)
Closes #2731
1 parent fe33cf6 commit 4a41c53

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

pypdf/_writer.py

+4
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,10 @@ def _update_field_annotation(
906906
"/Length": 0,
907907
}
908908
)
909+
if AA.AP in anno:
910+
for k, v in cast(DictionaryObject, anno[AA.AP]).get("/N", {}).items():
911+
if k not in {"/BBox", "/Length", "/Subtype", "/Type", "/Filter"}:
912+
dct[k] = v
909913

910914
# Update Resources with font information if necessary
911915
if font_res is not None:

tests/test_writer.py

+14
Original file line numberDiff line numberDiff line change
@@ -2286,3 +2286,17 @@ def test_field_box_upside_down():
22862286
box = writer.pages[0]["/Annots"][13].get_object()["/AP"]["/N"]["/BBox"]
22872287
assert box[2] > 0
22882288
assert box[3] > 0
2289+
2290+
2291+
@pytest.mark.enable_socket()
2292+
def test_matrix_entry_in_field_annots():
2293+
"""Cf #2731"""
2294+
url = "https://github.com/user-attachments/files/16036514/template.pdf"
2295+
name = "iss2731.pdf"
2296+
writer = PdfWriter(BytesIO(get_data_from_url(url, name=name)))
2297+
writer.update_page_form_field_values(
2298+
writer.pages[0],
2299+
{"Stellenbezeichnung_1": "some filled in text"},
2300+
auto_regenerate=False,
2301+
)
2302+
assert "/Matrix" in writer.pages[0]["/Annots"][5].get_object()["/AP"]["/N"]

0 commit comments

Comments
 (0)