Skip to content

表格提取工具使用指南

注意:在学习使用不同函数之前,建议先阅读请求描述,了解基本的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

响应参数数据类型描述
codeStringHTTP请求状态,"200"代表成功
messageString请求信息
dataObject返回结果
+taskIdString任务ID
+taskFileNumint任务处理文件数量
+taskSuccessNumint任务处理文件成功数量
+taskFailNumint任务处理文件失败数量
+taskStatusString任务状态
+assetTypeIdint使用资产类型ID
+taskCostint任务费用
+taskTimeint任务持续时间
+sourceTypeString原格式
+targetTypeString目标格式
+fileInfoDTOListArray任务文件信息
++fileKeyString文件key
++taskIdString任务ID
++fileNameString原文件名
++downFileNameString下载文件名
++fileUrlString原文件地址
++downloadUrlString处理结果文件下载地址
++sourceTypeString原格式
++targetTypeString目标格式
++fileSizeint文件大小
++convertSizeint处理结果文件大小
++convertTimeint处理消耗时间
++statusString文件处理状态
++failureCodeString文件处理失败错误码
++failureReasonString文件处理失败说明
++fileParameterString处理参数

响应示例:

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>"
  ]
}

异步请求

如果您需要使用文件异步处理流程,请阅读异步请求说明