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
The get_form_fields() function raises an error when launched on a pdf with pages without annotations
The error is :
Traceback (most recent call last):
File "[python script]", line 48, in <module>
fillpdf.fillpdfs.get_form_fields("form.pdf")
File "[root]\venv\lib\site-packages\fillpdf\fillpdfs.py", line 34, in get_form_fields
for annotation in annotations:
TypeError: 'NoneType' object is not iterable
I just took a look to the code of the function and the bug could be fixed by adding: if annotations: before the for annotation in annotations: loop.
the new code would be:
defget_form_fields(input_pdf_path):
""" Retrieves the form fields from a pdf to then be stored as a dictionary and passed to the write_fillable_pdf() function. Uses pdfrw. Parameters --------- input_pdf_path: str Path to the pdf you want the fields from. Returns --------- """data_dict= {}
pdf=pdfrw.PdfReader(input_pdf_path)
forpageinpdf.pages:
annotations=page[ANNOT_KEY]
ifannotations:
forannotationinannotations:
ifannotation[SUBTYPE_KEY] ==WIDGET_SUBTYPE_KEY:
ifannotation[ANNOT_FIELD_KEY]:
key=annotation[ANNOT_FIELD_KEY][1:-1]
data_dict[key] =''ifannotation[ANNOT_VAL_KEY]:
value=annotation[ANNOT_VAL_KEY]
data_dict[key] =annotation[ANNOT_VAL_KEY]
try:
iftype(annotation[ANNOT_VAL_KEY]) ==pdfrw.objects.pdfstring.PdfString:
data_dict[key] =pdfrw.objects.PdfString.decode(annotation[ANNOT_VAL_KEY])
except:
passprint("{"+",\n".join("{!r}: {!r}".format(k, v) fork, vindata_dict.items()) +"}")
The text was updated successfully, but these errors were encountered:
The
get_form_fields()
function raises an error when launched on a pdf with pages without annotationsThe error is :
I just took a look to the code of the function and the bug could be fixed by adding:
if annotations:
before thefor annotation in annotations:
loop.the new code would be:
The text was updated successfully, but these errors were encountered: