My function should be reading in field including ‘Date of Birth’, ‘Beneficial Owner Name’, and some other fields but they are getting skipped.
Function:
def read_pdf_form(path_to_pdf):
pdf = PdfReader(path_to_pdf)
annotations = [ann for page in pdf.pages for ann in page.Annots or []]
field_values = {ann.T[1:-1]: ann.V[1:-1] if ann.V else ” for ann in annotations if ann.T}
print(“Extracted field values from PDF:”, field_values, “n”)
return field_values
Fields Read:
Extracted field values from PDF: {‘Name of Investor’: ‘Unfilled’, ‘US TIN’: ‘Unfilled’, ‘Type of Subscriber’: ‘Unfilled’, ‘Controlling Individual Email’: ‘Unfilled’, ‘brendan’: ”, ‘Advisor Name’: ‘Unfilled’, ‘Advisor Rep Number’: ‘Unfilled’, ‘Commitment Amount’: ‘Unfilled’, ‘Bank Name’: ‘Unfilled’, ‘Bank Address’: ‘Unfilled’, ‘Bank City’: ‘Unfilled’, ‘Bank State’: ‘Unfilled’, ‘Bank Zip’: ‘Unfilled’, ‘Account Name’: ‘Unfilled’, ‘Account Number’: ‘Unfilled’, ‘ABA Routing Number’: ‘Unfilled’, ‘Beneficiary Account Name’: ‘Unfilled’, ‘Beneficiary Account Number’: ‘Unfilled’, ‘Advisor Phone Number’: ”, ‘Subscriber Letters’: ‘Unfilled’, ‘Signature1’: ”}
‘Beneficial Owner Name’ is after ‘Type of Subscriber’ and before ‘Controlling Individual’
I tried adding a loop to go through the document, tried to add a page constraint due to the fields being skipped being on one page, and tried renaming the fields in the PDF but none of it worked an it complexified the code so I reverted to my original read function.
user26663967 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.