Form Recognizer
With the Form Recognizer tool of ComPDFKit Document AI, you can recognize all the forms in Images. The following examples show how to upload a JPG file and run the Form Recognizer feature using Java, PHP, C#, Python, and Swift programming languages. Then, output a JSON file.
Java
// Create a client
CPDFClient client = new CPDFClient(publicKey,secretKey);
// Create a task
// Create an example of a DocumentAI Form Recognizer task
CPDFCreateTaskResult result = client.createTask(CPDFDocumentAIEnum.TABLEREC);
// Get a task id
String taskId = result.getTaskId();
// File handling parameter settings
CPDFFormRecognizerParameter fileParameter = new CPDFFormRecognizerParameter();
fileParameter.setLang("auto");
// Upload files
client.uploadFile(new File("test.jpg"), taskId, fileParameter);
// Execute task
client.executeTask(taskId);
// Query TaskInfo
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
PHP
// Create a client
$client = new CPDFClient('public_key', 'secret_key');
// Create a task
// Create an example of a DocumentAI Form Recognizer task
$taskInfo = $client->createTask(CPDFDocumentAI::TABLEREC);
// File handling parameter settings
$file = $client->addFile('test.jpg')
->setLang('auto');
// Upload files
$fileInfo = $file->uploadFile($taskInfo['taskId']);
// Execute task
$client->executeTask($taskInfo['taskId']);
// Query TaskInfo
$taskInfo = $client->getTaskInfo($taskInfo['taskId']);
C#
// Create a client
CPDFClient client = new CPDFClient(publicKey,secretKey);
// Create a task
// Create an example of a DocumentAI Form Recognizer task
CPDFCreateTaskResult result = client.CreateTask(CPDFDocumentAIEnum.TABLEREC);
// Get a task id
string taskId = result.TaskId;
// File handling parameter settings
CPDFFormRecognizerParameter fileParameter = new CPDFFormRecognizerParameter();
// Upload files
client.UploadFile(new FileInfo("test.jpg"), taskId, fileParameter);
// Execute task
client.ExecuteTask(taskId);
// Query TaskInfo
CPDFTaskInfoResult taskInfo = client.GetTaskInfo(taskId);
Python
# Create a client
client = CPDFClient(public_key, secret_key)
# Create a task
# Create an example of a DocumentAI Form Recognizer task
create_task_result = client.create_task(CPDFDocumentAIEnum.TABLEREC)
# Get a task id
task_id = create_task_result.task_id
# File handling parameter settings
file_parameter = CPDFFormRecognizerParameter()
# Upload files
client.upload_file('test.jpg', task_id, file_parameter)
# Execute task
client.execute_task(task_id)
# Query TaskInfo
task_info = client.get_task_info(task_id)
Swift
// Create a client
let client: CPDFClient = CPDFClient(publicKey: public_key, secretKey: secret_key)
Task { @MainActor in
// Create a task
// Create an example of a DocumentAI Form Recognizer task
let taskModel = await client.createTask(url: CPDFDocumentAI.TABLEREC, language: .english)
// Get a task id
let taskId = taskModel?.taskId ?? ""
// Upload files
let path = Bundle.main.path(forResource: "IMG_00001(2)", ofType: "jpg")
let uploadFileModel = await client.uploadFile(filepath: path ?? "", language: .english, params: [:], taskId: taskId)
// Execute task
let _ = await client.processFiles(taskId: taskId, language: .english)
// Query TaskInfo
let taskInfoModel = await client.getTaskInfo(taskId: taskId, language: .english)
}
Needed Parameters:
lang
: Supported types and definitions.auto - Automatic classification language.
english - English.
chinese - Simplified Chinese.
chinese_tra - Traditional Chinese.
korean - Korean.
japanese - Japanese.
latin - Latin.
devanagari - Sanskrit alphabet.
Result:
File Type | Description |
---|---|
.json | Form Recognition results. |
Content:
Parameter | Description |
---|---|
cost | Time spent on form identification. |
type | Types of form. |
angle | The angle at which the form is rotated. |
width | Width of the form. |
height | Height of the form. |
rows | Number of rows in the form. |
cols | Number of columns in the form. |
position | The rectangular box position of the form. |
height_of_rows | Height of each row of the form. |
width_of_cols | Width of each column of the form. |
table_cells | Information about all cells in the form. |
table_cells: start_row | The start row of a cell. |
table_cells: end_row | The end row of a cell. |
table_cells: start_col | The start column of a cell. |
table_cells: end_col | The end column of a cell. |
table_cells: text | Text in cells. |
table_cells: position | Rectangular box position information for cells. |
table_cells: lines | The text lines included in the cell. |
table_cells: lines: text | The text line. |
table_cells: lines: score | The score is identified by the text line. |
table_cells: lines: position | Text line position information. |