I want to detect coordinates of a fill-able PDF forms, more precisely bounding box coordinates of a text-box where a particular text field (String) is going to be placed.
Currently I'm following a hard-coded Python-Pdfminer approach using LTTBox to detect the coordinates based on certain string presence.
Example:
def identifyTextboxes(path, fieldName, fieldType):
# reading the file and setting prams
fp = open(path, 'rb')
rsrcmgr = PDFResourceManager()
laparams = LAParams()
device = PDFPageAggregator(rsrcmgr, laparams=laparams)
interpreter = PDFPageInterpreter(rsrcmgr, device)
pages = PDFPage.get_pages(fp)
# defining key-terms of custodian:
names=["Name of entity:", "Name of Investor (Please Print or Type)", "Print Name of Entity", "Name of Prospective Investor ",
"Investor's Name", "Name (the “Applicant” or “We”)", "On Behalf of:", "Name of Business"]
num_pages = 0
output = []
for page in pages:
temp_dict = {}
interpreter.process_page(page)
layout = device.get_result()
num_pages += 1
# fetching the coordinates of the text via bbox
for lobj in layout:
if isinstance(lobj, LTTextBox):
(x, y, xw, yh), text = lobj.bbox, lobj.get_text()
for name in names:
ResSearch = re.search(name, text)
if ResSearch:break
field='textbox'
if ResSearch:break
if ResSearch:
temp_dict['label'] = fieldName
temp_dict['type'] = fieldType
temp_dict["value"] = ''
temp_dict['group'] = ''
temp_dict["overlay"] = {'page': num_pages, 'left': (xw)-90, 'top':((y-10)-(yh-y))+90, 'height': 20, 'width':240}
output.append(temp_dict)
print(lobj)
return output
In the code above, i detect places where the matching string appears from the list names and define the coordinate of the text-box on the right to the appearance based on LTTBox coordinates and a fixed with, as you can see on the return output['overlay'].
This process is very much hard-coded and fails when any unknown string or situation occurs in a PDF, hence not that robust.
I want to drive a more data driven statistical approach to detect the coordinates of a bounding box via CNN/RNN/CNN+RNN. I have gone through EAST detector, but that doesn't seem to solve the problem, so maybe training a more customized network should be perhaps more useful.
Please find the pictures attached for a better understanding if what the current code does.

I'm new to ML, i need guidance to construct a network of this kind. Any help is highly appreciated.