forked from aws-samples/amazon-textract-code-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13-signature.py
More file actions
41 lines (32 loc) · 1021 Bytes
/
13-signature.py
File metadata and controls
41 lines (32 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import boto3
import json
from trp import Document
from tabulate import tabulate
#create a Textract Client
textract = boto3.client('textract')
#Document
documentName = image_filename
response = None
with open(image_filename, 'rb') as document:
imageBytes = bytearray(document.read())
# Call Textract AnalyzeDocument by passing a document from local disk
response = textract.analyze_document(
Document={'Bytes': imageBytes},
FeatureTypes=["FORMS",'SIGNATURES']
)
#print detected text
d = []
for item in response["Blocks"]:
if item["BlockType"] == "SIGNATURE":
d.append([item["Id"],item["Geometry"]])
print(tabulate(d, headers=["Id", "Geometry"],tablefmt="grid", maxcolwidths= [None,100]))
doc = Document(response)
d = []
for page in doc.pages:
# Search fields by key
print("\nSearch Fields:")
key = "Signature"
fields = page.form.searchFieldsByKey(key)
for field in fields:
d.append([field.key, field.value])
print(tabulate(d, headers=["Key", "Value"]))