表格提取
使用 ComPDFKit Document AI 的表格提取工具,您可以识别图像中的所有表格。以下示例展示了如何上传 JPG 文件并使用 Java、PHP、C#、Python 和 Swift 编程语言运行表单识别器功能。然后输出 JSON 文件。
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)
}
所需参数:
lang
:支持的类型和定义。auto - 自动分类语言。
english - 英语。
chinese - 简体中文。
chinese_tra - 繁体中文。
korean - 韩语。
japanese - 日语。
latin - 拉丁语。
devanagari - 梵文字母。
结果:
文件类型 | 说明 |
---|---|
.json | 表单识别结果。 |
内容:
参数 | 说明 |
---|---|
cost | 表单识别所花费的时间。 |
type | 表单类型。 |
angle | 表单旋转的角度。 |
width | 表单的宽度。 |
height | 表单的高度。 |
rows | 表单中的行数。 |
cols | 表单中的列数。 |
position | 表单的矩形框位置。 |
height_of_rows | 表单每行的高度。 |
width_of_cols | 表单每列的宽度。 |
table_cells | 表单中所有单元格的信息。 |
table_cells: start_row | 单元格的起始行。 |
table_cells: end_row | 单元格的结束行。 |
table_cells: start_col | 单元格的起始列。 |
table_cells: end_col | 单元格的结束列。 |
table_cells: text | 单元格中的文本。 |
table_cells: position | 单元格的矩形框位置信息。 |
table_cells: lines | 单元格中包含的文本行。 |
table_cells: lines: text | 文本行。 |
table_cells: lines: score | 分数由文本行标识。 |
table_cells: lines: position | 文本行位置信息。 |