智能全文解析工具使用指南
注意:在学习使用不同函数之前,建议先阅读请求描述,了解基本的PDF处理流程。使用不同函数时,可以在上传文件时设置各自特殊的参数。其他基本步骤一致。
智能全文解析:
java
{
"getImage": "both",
"isAllowOcr": 1,
"imageOutputType": "base64str"
}
所需参数:
getImage
: 提取图片类型: page 返回每一页的整页图像,objects 返回页面内的图像对象,both 返回整页图像和图像对象。
isAllowOcr
: 是否开启OCR(0: 不开启;1: 开启)。
imageOutputType
: 图片存储类型 base64str,url
base64str:此时图片直接以base64格式在API结果中返回。(这种方式返回结果体积会很大,长文档不推荐)
url:此时图片直接以平台的链接方式返回,您可以通过链接下载图片到本地,或上传到您的云存储。
Java 示例:
您需要将 apiKey 替换为您从控制台获取的 publicKey ,将 file 替换为您要转换的文件 ,language 替换为您想要的接口错误提示语言类型。
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","{ \"getImage\": \"objects\",\"isAllowOcr\":1,\"imageOutputType\":\"url\"}")
.build();
Request request = new Request.Builder()
.url("https://api-server.compdf.com/server/v1/process/idp/documentParsing")
.method("POST", body)
.addHeader("x-api-key", "{{apiKey}}")
.build();
Response response = client.newCall(request).execute();
}
}
结果:
文件类型 | 文件描述 |
---|---|
.json | 智能文档解析完成的 json 文件 |
返回数据结构说明:
java
◆ code (integer) 操作状态码
◆ message (string) 描述信息
◆ version (string) 版本号
◆ duration (integer) 总处理耗时(单位:毫秒)
◆ x_request_id (string) 请求ID
◆ image_process (array) 是否有水印
◆ msg (string) 描述信息
◆ result (object) 核心数据
├─ markdown (string)整份文档的Markdown格式文本
├─ total_count (integer) PDF文档总页数
├─ total_page_number (integer) PDF文档总页数
├─ success_count (integer) 成功处理总页数
├─ total_count (integer) PDF文档总页数
├─ valid_page_number (integer) 成功解析的有效页数
├─ excel_base64 (string) Excel文件base64编码
├─ catalog (object) 目录树结构
│ └─ toc (array)
│ ├─ pos (array):该目录区域的四个角点坐标,依次left-top,right-top,right-bottom,left-bottom.
│ ├─ paragraph_id (integer):标题所在段落id
│ ├─ page_id (integer):标题所在页码 (最小页码为 1)
│ ├─ hierarchy (integer):标题层级, 1 是 1级标题, 2 是 2级标题,依次类推
│ ├─ pos_list (array):发生标题合并时,为合并前多个标题的坐标。未发生标题合并时,即为该标题的坐标
│ ├─ title (string):标题内容
│ └─ sub_type (string):标题类型 text_title、 image_title、 table_title
│
├─ pages (array) 分页数据容器
│ ├─ status (string):页面处理状态/错误信息
│ ├─ page_id (number):当前页码
│ ├─ durations (number):页面处理耗时(毫秒)
│ ├─ image_id (string):图片地址
│ ├─ width (integer):文档页宽度(像素)
│ ├─ height (integer):文档页高度(像素)
│ ├─ angle (integer):文本方向角度(0°: ▲ (正立)/90°: ▶ (右旋)/180°: ▼ (倒立)/270°: ◀ (左旋))
│ ├─ content (array):基础数据: 文字行, 图像中的其中一种,请参考textline和image的说明
│ └─ structured (array):结构化数据, 为textblock, table, imageblock, footer, header中的一种
│
└─ detail (array) Markdown详细信息(结构复用"段落数据"模型)
├─ page_id (integer):当前段落所在页码
├─ paragraph_id (integer):当前段落id
├─ outline_level (integer):标题级别: (最多支持5级标题) -1.正文 0.一级标题 1.二级标题 ...
├─ text (string):文本
├─ type (string):类型, paragraph(段落类型,包括正文、标题、公式等文字信息)、image(图片类型)、table(表格类型)
├─ image_url (string):图片地址
├─ content (integer):内容类型 0 正文(段落、图片、表格) 1 非正文(页眉、页脚、侧边栏)
├─ position (array):该目录区域的四个角点坐标,依次left-top,right-top,right-bottom,left-bottom.
├─ sub_type (string):子类型。当type为paragraph时,取值范围为catalog(目录),header(页眉),footer(页脚),sidebar(侧边栏),text(正文普通文本),text_title(文本标题),image_title(图片标题),table_title(表格标题);当type是image时,取值范围为stamp(印章),chart(图表),qrcode(二维码),barcode(条形码);当type为table时,取值范围为bordered(有线表), borderless(无线表)。
├─ tags (array):表示段落内是否存在特殊文本,类型包括公式formula和手写体handwritten
│─ cells (array):单元格数组, 仅在type为table时返回
│ ├─ row_span (integer):单元格行跨度,默认为1
│ ├─ text (integer):
│ ├─ type (integer):
│ ├─ col (integer):单元格列号
│ ├─ col_span (integer):单元格列跨度,默认为1
│ ├─ page_id (integer):
│ ├─ position (integer):单元格的四个角点坐标,依次left-top,right-top,right-bottom,left-bottom.
│ └─ row (integer):单元格行号
│
└─ caption_id (object):原始OCR文本结果
├─ page_id (integer):标题所在页码
└─ paragraph_id (integer):标题所在段落id
◆ metrics (array) 页面级性能指标
├─ page_image_width (integer):当前页渲染宽度(像素)
├─ page_image_height (integer):当前页渲染高度(像素)
├─ dpi (integer):图片分辨率
├─ durations (number):页面处理耗时(毫秒)
├─ status (string):页面处理状态
├─ page_id (number):当前页码
├─ angle (integer):文本方向角度(0°: ▲ (正立)/90°: ▶ (右旋)/180°: ▼ (倒立)/270°: ◀ (左旋))
└─ image_id (string):页面图片ID(下载方式同pages.image_id)
结构化数据规格说明 :
Content(文字行/图像)
Image 图像数据
参数名 | 类型 | 描述 |
---|---|---|
id | integer | 数据ID |
type | string | 数据类型 (固定值: image) |
pos | array | 文本行四个角点坐标 格式: [左上(x,y), 右上(x,y), 右下(x,y), 左下(x,y)] |
size | array | 图像尺寸 [width, height] |
data | object | 图像内容物件 |
↳ data.region | array | 图像在页面中的区域坐标 |
↳ data.path | string | 图像档案路径 |
↳ data.base64 | string | 图像档案(jpg/png)的base64字串 |
Textline 文本行数据
参数名 | 类型 | 描述 |
---|---|---|
id | integer | 数据ID(页面内唯一) |
type | string | 数据类型 (固定值: line) |
text | string | 文本行文字内容 (当sub_type=stamp时为印章文字) |
pos | array | 文本行四个角点坐标 |
score | number | 字符可信度 (仅输入入图像进行OCR时产生) |
structured 数据
Textblock 文本区块
参数名 | 类型 | 描述 |
---|---|---|
id | integer | 数据ID |
type | string | 区块类型 (固定值: textblock) |
pos | array | 文字区块四个角点坐标 |
content | array | 包含的文本行ID阵列 |
sub_type | string | 子类型 (title/list/formula等) |
text | string | 区块文本内容 |
outline_level | integer | 标题层级:-1 =正文, 0 =一级标题, 1 =二级标题...(最多支持五级) |
Table 表格数据
参数名 | 类型 | 描述 |
---|---|---|
id | integer | 数据ID |
type | string | 区块类型 (固定值: table) |
sub_type | string | 表格类型 (预设值:bordered,无线表格需特別标注) |
pos | array | 表格四個角点坐标 |
rows | integer | 总行数 |
cols | integer | 总列数 |
columns_width | array | 列宽度阵列 |
rows_height | array | 行高度阵列 |
text | string | 表格内容(HTML/Markdown格式) |
Imageblock 图像区块
参数名 | 类型 | 描述 |
---|---|---|
id | integer | 数据ID |
type | string | 区块类型 (固定值: image) |
pos | array | 图像区块四个角点坐标 |
text | string | 图像标注文字 (HTML/Markdown格式) |
image_url | string | 图像档案路径 |
base64str | string | 图像base64编码字符串 |
Footer 页尾区块
参数名 | 类型 | 描述 |
---|---|---|
type | string | 区块类型 (固定值: footer) |
pos | array | 区块四个角点坐标 |
blocks | array | 内容区块阵列 (可包含 textblock/imageblock/table) |
Header 页首区块
参数名 | 类型 | 描述 |
---|---|---|
type | string | 区块类型 (固定值: header) |
pos | array | 区块四個角点坐标 |
image_url | string | 页首图像路径 |
base64str | string | 页首图像base64编码 |
blocks | array | 内容区块阵列 (可包含 textblock/imageblock/table) |