Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Cope with Matrix entry in field annotations #2736

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
Loading