-
Notifications
You must be signed in to change notification settings - Fork 25
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
Radio buttons. - KeyError: "2 Not An Option, Options are ['0', '1']" #63
Comments
here is my work around. I updated after for each, I added this check. if annotation[ANNOT_FORM_options] or ( Like this. I will post a fork. key_value = data_dict[key]
for each in annotation['/Kids']:
if not annotation[ANNOT_FORM_options]:
continue
keys2 = each['/AP']['/N'].keys()
if '/Off' in keys2:
keys2.remove('/Off')
if ['/Off'] in keys:
keys2.remove('/Off')
export = keys2[0]
if '/' in export:
options.append(export[1:])
else:
options.append(export)
form_options = None
if annotation[ANNOT_FORM_options] or (
each['/Parent'] and each['/Parent']['/Opt']):
if annotation[ANNOT_FORM_options]:
form_options = [(x.strip('()')) for x in annotation[ANNOT_FORM_options]]
if each['/Parent'] and each['/Parent']['/Opt']:
# custom choices = /AP/N choices
form_options = [(x.strip('()')) for x in each['/Parent']['/Opt']]
if form_options:
options = form_options
if (is_int_convertible(data_dict[key]) and key_value == data_dict[key]):
try:
key_value = str(form_options.index(data_dict[key]))
except ValueError:
pass
# print('index not found')
if f'/{key_value}' == export:
val_str = pdfrw.objects.pdfname.BasePdfName(f'/{key_value}')
else:
val_str = pdfrw.objects.pdfname.BasePdfName(f'/Off')
if set(keys).intersection(set(temp_dict.values())):
each.update(pdfrw.PdfDict(AS=val_str))
# if data_dict[key] not in options:
# if key_value != "None" and data_dict[key] != "":
# print(KeyError(f"{data_dict[key]} Not An Option for key '{key}, "
# f"on page '{pg_count}' loop '{pg_loop}' Options are {options}"))
# else:
if set(keys).intersection(key_value):
annotation.update(
pdfrw.PdfDict(V=pdfrw.objects.pdfname.BasePdfName(f'/{key_value}'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi I'm getting this error on some Radio buttons.
File "C:\sites\backend\env\lib\site-packages\fillpdf\fillpdfs.py", line 251, in write_fillable_pdf
raise KeyError(f"{data_dict[key]} Not An Option, Options are {options}")
KeyError: "2 Not An Option, Options are ['0', '1']"
In the PDF, the values are shown as 1 and 2
When I inspect for each in annotation['/Kids']: keys2 = each['/AP']['/N'].keys(). I can't find where these choices are saved.
Any suggestion how to work around this?
The text was updated successfully, but these errors were encountered: