表格提取工具使用指南
注意:在学习使用不同函数之前,建议先阅读请求描述,了解基本的PDF处理流程。使用不同函数时,可以在上传文件时设置各自特殊的参数。其他基本步骤一致。
表格提取:
java
{
"ocrRecognitionLang": "AUTO",
}
所需参数:
ocrRecognitionLang
:OCR识别语言,支持的类型和定义:
AUTO: 自动,CHINESE: 中文简体,CHINESE_TRAD: 中文繁体,ENGLISH: 英语,KOREAN: 韩语,JAPANESE: 日语,LATIN: 拉丁语,DEVANAGARI: 梵文,CYRILLIC: 西里尔语,ARABIC: 阿拉伯语,TAMIL: 泰米尔语,TELUGU: 泰卢固语,KANNADA: 卡纳达语;默认 AUTO。
请求示例:
您需要将 apiKey 替换为您从控制台获取的 publicKey ,将 file 替换为您要转换的文件 ,language 替换为您想要的接口错误提示语言类型。
curl
curl --location --request POST 'https://api-server.compdf.com/server/v2/process/documentAI/tableRec' \
--header 'x-api-key: apiKey' \
--header 'Accept: */*' \
--header 'Connection: keep-alive' \
--header 'Content-Type: multipart/form-data' \
--form 'file=@"file"' \
--form 'password="" \
--form 'parameter="{ \"ocrRecognitionLang\": \"AUTO\" }"' \
--form 'language="1"'
java
import java.io.*;
import okhttp3.*;
public class main {
public static void main(String []args) throws IOException{
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("file","{{file}}",
RequestBody.create(MediaType.parse("application/octet-stream"),
new File("<file>")))
.addFormDataPart("language","{{language}}")
.addFormDataPart("password","")
.addFormDataPart("parameter","{ \"ocrRecognitionLang\": \"AUTO\" }")
.build();
Request request = new Request.Builder()
.url("https://api-server.compdf.com/server/v2/process/documentAI/tableRec")
.method("POST", body)
.addHeader("x-api-key", "{{apiKey}}")
.build();
Response response = client.newCall(request).execute();
}
}
响应信息:
请求的成功响应返回 HTTP 200 OK
状态代码以及显示订单详细信息的 JSON 响应主体。
响应模式:application/json
响应参数 | 数据类型 | 描述 |
---|---|---|
code | String | HTTP请求状态,"200"代表成功 |
message | String | 请求信息 |
data | Object | 返回结果 |
+taskId | String | 任务ID |
+taskFileNum | int | 任务处理文件数量 |
+taskSuccessNum | int | 任务处理文件成功数量 |
+taskFailNum | int | 任务处理文件失败数量 |
+taskStatus | String | 任务状态 |
+assetTypeId | int | 使用资产类型ID |
+taskCost | int | 任务费用 |
+taskTime | int | 任务持续时间 |
+sourceType | String | 原格式 |
+targetType | String | 目标格式 |
+fileInfoDTOList | Array | 任务文件信息 |
++fileKey | String | 文件key |
++taskId | String | 任务ID |
++fileName | String | 原文件名 |
++downFileName | String | 下载文件名 |
++fileUrl | String | 原文件地址 |
++downloadUrl | String | 处理结果文件下载地址 |
++sourceType | String | 原格式 |
++targetType | String | 目标格式 |
++fileSize | int | 文件大小 |
++convertSize | int | 处理结果文件大小 |
++convertTime | int | 处理消耗时间 |
++status | String | 文件处理状态 |
++failureCode | String | 文件处理失败错误码 |
++failureReason | String | 文件处理失败说明 |
++fileParameter | String | 处理参数 |
响应示例:
json
"code": "200",
"msg": "success",
"data": {
"taskId": "f416dbcf-0c10-4f93-ab9e-a835c1f5dba1",
"taskFileNum": 1,
"taskSuccessNum": 1,
"taskFailNum": 0,
"taskStatus": "<taskStatus>",
"assetTypeId": 0,
"taskCost": 1,
"taskTime": 1,
"sourceType": "<sourceType>",
"targetType": "<targetType>",
"fileInfoDTOList": [
{
"fileKey": "<fileKey>",
"taskId": "<taskId>",
"fileName": "<fileName>",
"downFileName": "<downFileName>",
"fileUrl": "<fileUrl>",
"downloadUrl": "<downloadUrl>",
"sourceType": "<sourceType>",
"targetType": "<targetType>",
"fileSize": 24475,
"convertSize": 6922,
"convertTime": 8,
"status": "<status>",
"failureCode": "",
"failureReason": "",
"fileParameter": "<fileParameter>"
}
]
}
结果:
文件类型 | 文件描述 |
---|---|
.json | 完成后的 Json 文件 |
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 | 文本行位置信息 |
json
{
"cost": 7566,
"json_items": [
{
"type": "table_with_line",
"angle": 0.0,
"width": 488,
"height": 191,
"rows": 4,
"cols": 4,
"position": [
114,
657,
602,
657,
602,
848,
114,
848
],
"height_of_rows": [
65,
30,
31,
36
],
"width_of_cols": [
122,
122,
118,
122
],
"table_cells": [
{
"start_row": 1,
"end_row": 1,
"start_col": 1,
"end_col": 1,
"text": "",
"position": [
2,
2,
124,
2,
124,
67,
2,
67
],
"lines": []
},
{
"start_row": 2,
"end_row": 2,
"start_col": 1,
"end_col": 1,
"text": "Absorbed",
"position": [
2,
64,
125,
64,
125,
95,
2,
95
],
"lines": [
{
"text": "Absorbed",
"score": 1.0,
"position": [
29,
65,
99,
65,
99,
88,
29,
88
]
}
]
}
]
}
],
"html_items": [
"<table border=\ "1\" width='488px' height='191px'>\n
<tr>
<th width='122px' height='65px'></th>
<th width='122px' height='65px' style=\ "white-space: pre-line\">Absorbed</th>
<th width='118px' height='65px' style=\ "white-space: pre-line\">Neuter</th>
<th width='122px' height='65px' style=\ "white-space: pre-line\">Fatigue</th>
</tr>\n
<tr>
<th width='122px' height='30px' style=\ "white-space: pre-line\">Absorbed</th>
<th width='122px' height='30px'>
</th>
<th width='118px' height='30px' style=\ "white-space: pre-line\">2</th>
<th width='122px' height='30px'>
</th>
</tr>\n
<tr>
<th width='122px' height='31px' style=\ "white-space: pre-line\">Neuter</th>
<th width='122px' height='31px'>
</th>
<th width='118px' height='31px'>
</th>
<th width='122px' height='31px'>
</th>
</tr>\n
<tr>
<th width='122px' height='36px' style=\ "white-space: pre-line\">Fatigue</th>
<th width='122px' height='36px'>
</th>
<th width='118px' height='36px'>
</th>
<th width='122px' height='36px' style=\ "white-space: pre-line\">8</th>\t</tr>\n</table>", "
<table border=\ "1\" width='489px' height='166px'>\n
<tr>
<th width='123px' height='61px' style=\ "white-space: pre-line\">Expression</th>
<th width='117px' height='61px' style=\ "white-space: pre-line\">Image Num</th>
<th width='118px' height='61px' style=\ "white-space: pre-line\">Correct</th>
<th width='125px' height='61px' style=\ "white-space: pre-line\">Recognition Rate</th>
</tr>\n
<tr>
<th width='123px' height='31px' style=\ "white-space: pre-line\">Absorbed</th>
<th width='117px' height='31px' style=\ "white-space: pre-line\">9</th>
<th width='118px' height='31px' style=\ "white-space: pre-line\">7</th>
<th width='125px' height='31px' style=\ "white-space: pre-line\">77.8%</th>
</tr>\n
<tr>
<th width='123px' height='30px' style=\ "white-space: pre-line\">Neuter</th>
<th width='117px' height='30px' style=\ "white-space: pre-line\">9</th>
<th width='118px' height='30px'>
</th>
<th width='125px' height='30px' style=\ "white-space: pre-line\">55.6%</th>
</tr>\n
<tr>
<th width='123px' height='31px' style=\ "white-space: pre-line\">Fatigue</th>
<th width='117px' height='31px' style=\ "white-space: pre-line\">9</th>
<th width='118px' height='31px'>
</th>
<th width='125px' height='31px' style=\ "white-space: pre-line\">88.9%</th>
</tr>\n
<tr>
<th width='483px' height='33px' colspan=\ "4\" style=\ "white-space: pre-line\">Average recognition rate: 74.1%</th>\t</tr>\n</table>"
]
}
异步请求
如果您需要使用文件异步处理流程,请阅读异步请求说明。