pypdf silently fails to check boxes when wrong on-state string is passed
A quirk in pypdf's update_page_form_field_values() allows developers to set a checkbox value using strings like 'Yes', 'true', '1', or Python's True boolean, yet the box remains visually unchecked in PDF viewers. The function returns no error, raises no exception, and logs nothing, even though the underlying field value and appearance state are never actually updated. This happens because PDF checkboxes have no universal on-state name — the checked value is defined per field inside the document's own appearance dictionary, commonly '/Yes' but sometimes '/On', '/1', or a custom string. The only reliable fix is to read the correct on-state string directly from the PDF field's '_States_' list at runtime, rather than hardcoding an assumed value. Developers using pypdf 6.18.0 should update their form-filling logic to dynamically retrieve the field-specific on-state before calling the update function.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in