You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I needed to fill forms (e.g., US tax forms) with hierarchical fields (e.g., person1.address.city). This doesn't seem to be supported in fdfgen. So I modified the handle_data_strings function to handle inputs such as this:
def handle_data_strings(fdf_data_strings, fields_hidden, fields_readonly,
checkbox_checked_name):
if isinstance(fdf_data_strings, dict):
fdf_data_strings = fdf_data_strings.items()
for (key, value) in fdf_data_strings:
if value is True:
value = b'/V' + FDFIdentifier(checkbox_checked_name).value
elif value is False:
value = b'/V' + FDFIdentifier('Off').value
elif isinstance(value, FDFIdentifier):
value = b'/V' + value.value
elif isinstance(value, list) or isinstance(value, tuple) or isinstance(value, dict):
value = \
b'/Kids[\n' \
+ b''.join(handle_data_strings(value, fields_hidden, fields_readonly,
checkbox_checked_name)) \
+ b']'
else:
value = b'/V' + b''.join([b'(', smart_encode_str(value), b')'])
yield b''.join([
b'<<',
b'/T(',
smart_encode_str(key),
b')',
value,
handle_hidden(key, fields_hidden),
b'',
handle_readonly(key, fields_readonly),
b'>>\n',
])
I tested it only briefly. So no guarantees. Feel free to integrate it into the code base.
An alternative is to use the somewhat simpler (IMHO) xfdf form data format (also supported by pdftk).
I needed to fill forms (e.g., US tax forms) with hierarchical fields (e.g., person1.address.city). This doesn't seem to be supported in fdfgen. So I modified the handle_data_strings function to handle inputs such as this:
I tested it only briefly. So no guarantees. Feel free to integrate it into the code base.
An alternative is to use the somewhat simpler (IMHO) xfdf form data format (also supported by pdftk).
I wrote a simple hand-coded Python function to generate that and used pdftk to fill the form. I can share the function is anyone is interested.
The text was updated successfully, but these errors were encountered: