Open sarahkittyy opened 22 hours ago
Without a reproducing file we cannot deal with this post.
In this case we need an example where a "non-/Yes" value is provided which we do not handle as "ON".
Supporting non-/Yes as ON on input is an enhancement request, not a bug: the PDF spec clearly recommends using /Yes
as the ON value:
Description of the bug
Ran into this tricky issue. It's not true that
/Yes
is a valid ON state for every single checkbox widget in PDFs, like as implemented / specified in the docs.Rather, 99% of PDF rendering engines automatically take "Yes" as an acceptable On state, even if it is not specified in the
/AP/N
dict of the widget.Try iterating over all widgets in a PDF with checkboxes, like any IRS tax form and set them to "Yes". It will render correctly in browsers, but then try rendering it in SodaPDF's online editor, and the checkmarks will not appear. It's an example of a renderer that does not assume "Yes" is a valid default on state.
For my form specifically, a valid yes state is actually "/V /5". I tried setting
widget.field_value = '5'
and alsowidget.field_value = '/5'
but there is some internal code that is automatically changing this value to OFF, and not respecting my input.widget.on_state()
does not work since it just provides Yes and not '5' like I need.Then I tried manually setting the XREF like
pdf.xref_set_key(widget.xref, 'V', '5')
. But after a widget.update(), this is changed. And without callingwidget.update()
, this xref change is not reflected in the resulting saved document.In other pdf libraries like
pdfrw
, the change to /V is respected and checking the checkbox works as expected.This is clearly a bug and the widget
update()
method needs to respect the value present inwidget.field_value
. In the mean time, do you have any recommendations to update a widget in the full document without callingwidget.update()
? Like if I dopdf.xref_set_key
to change the widget's/V
value manually, how can I have that change remain persistent until I callpdf.save()
?Thank you.
How to reproduce the bug
PyMuPDF version
1.24.13
Operating system
Linux
Python version
3.12