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

ROB : update_page_form_field_values not failing if no fields #1346

Merged
merged 2 commits into from
Sep 18, 2022
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
3 changes: 3 additions & 0 deletions PyPDF2/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ def update_page_form_field_values(
"""
self.set_need_appearances_writer()
# Iterate through pages, update field values
if PG.ANNOTS not in page:
logger_warning("No fields to update on this page", __name__)
return
for j in range(len(page[PG.ANNOTS])): # type: ignore
writer_annot = page[PG.ANNOTS][j].get_object() # type: ignore
# retrieve parent field values, if present
Expand Down
6 changes: 6 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,17 @@ def test_fill_form():
page = reader.pages[0]

writer.add_page(page)
writer.add_page(PdfReader(RESOURCE_ROOT / "crazyones.pdf").pages[0])

writer.update_page_form_field_values(
writer.pages[0], {"foo": "some filled in text"}, flags=1
)

# check if no fields to fill in the page
writer.update_page_form_field_values(
writer.pages[1], {"foo": "some filled in text"}, flags=1
)

writer.update_page_form_field_values(
writer.pages[0], {"foo": "some filled in text"}
)
Expand Down