21
21
# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console
22
22
# file_path = '/path/to/local/pdf'
23
23
24
+
24
25
def process_document_form_sample (
25
26
project_id : str , location : str , processor_id : str , file_path : str
26
27
):
@@ -69,9 +70,9 @@ def process_document_form_sample(
69
70
for table in page .tables :
70
71
num_collumns = len (table .header_rows [0 ].cells )
71
72
num_rows = len (table .body_rows )
72
- print (f' Table with { num_collumns } columns and { num_rows } rows:' )
73
+ print (f" Table with { num_collumns } columns and { num_rows } rows:" )
73
74
print_table_info (table , text )
74
- print (f' Found { len (page .form_fields )} form fields:' )
75
+ print (f" Found { len (page .form_fields )} form fields:" )
75
76
for field in page .form_fields :
76
77
name = layout_to_text (field .field_name , text )
77
78
value = layout_to_text (field .field_value , text )
@@ -80,17 +81,17 @@ def process_document_form_sample(
80
81
81
82
def print_table_info (table : dict , text : str ) -> None :
82
83
# Print header row
83
- header_row_text = ''
84
+ header_row_text = ""
84
85
for header_cell in table .header_rows [0 ].cells :
85
86
header_cell_text = layout_to_text (header_cell .layout , text )
86
- header_row_text += f' { repr (header_cell_text .strip ())} | '
87
- print (f' Collumns: { header_row_text [:- 3 ]} ' )
87
+ header_row_text += f" { repr (header_cell_text .strip ())} | "
88
+ print (f" Collumns: { header_row_text [:- 3 ]} " )
88
89
# Print first body row
89
- body_row_text = ''
90
+ body_row_text = ""
90
91
for body_cell in table .body_rows [0 ].cells :
91
92
body_cell_text = layout_to_text (body_cell .layout , text )
92
- body_row_text += f' { repr (body_cell_text .strip ())} | '
93
- print (f' First row data: { body_row_text [:- 3 ]} \n ' )
93
+ body_row_text += f" { repr (body_cell_text .strip ())} | "
94
+ print (f" First row data: { body_row_text [:- 3 ]} \n " )
94
95
95
96
96
97
def layout_to_text (layout : dict , text : str ) -> str :
0 commit comments