文档解析(PaddleOCR-VL)
接口描述
PaddleOCR-VL:多模态文档解析SOTA方案,专为应对复杂文档解析任务而设计。可精准识别图像中的印刷文本、手写文本、表格、公式和图表等复杂元素,自动分类并智能推断符合人类阅读习惯的排列顺序,将复杂的页面内容转化为有序、带标签的元素序列;支持中、英、日、韩、拉丁文等 109 种语言解析,满足全球化多语种文档处理需求。
文档解析(PaddleOCR-VL):基于PaddleOCR-VL最新模型,通过标准化API服务,提供开箱即用、免部署的快捷接入方式,可直接返回 Markdown/JSON 结构化输出,助您快速实现复杂文档智能解析。
文档解析(PaddleOCR-VL)API服务为异步接口,需要先调用提交请求接口获取 task_id,然后调用获取结果接口进行结果轮询,建议提交请求后 5~10 秒轮询。提交请求接口QPS为2,获取结果接口QPS为10。
在线调试
您可以在 示例代码中心 中调试该接口,可进行签名验证、查看在线调用的请求内容和返回结果、示例代码的自动生成。
提交请求接口
请求说明
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/brain/online/v2/paddle-vl-parser/task
URL参数:
| 参数 | 值 |
|---|---|
| access_token | 通过API Key和Secret Key获取的access_token,参考“Access Token获取” |
Header如下:
| 参数 | 值 |
|---|---|
| Content-Type | application/x-www-form-urlencoded |
Body中放置请求参数,参数详情如下:
请求参数
| 参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
|---|---|---|---|---|
| file_data | 和file_url二选一 | string | - | 文件的base64编码数据:-版式文档:pdf、jpg、jpeg、png、bmp、tif、tiff,图片最长边不大于4096px文档大小不超过100M,其中PDF文档最大支持500页若文档大小超过50M,须从file_url方式上传。优先级: file_data > file_url,当file_data字段存在时,file_url字段失效 |
| file_url | 和file_data二选一 | string | - | 文件数据URL,URL长度不超过1024字节,支持单个URL传入PDF文档大小不超过100M,最大支持500页优先级: file_data > file_url,当file_data字段存在时,file_url字段失效请注意关闭URL防盗链 |
| file_name | 是 | string | - | 文件名,请保证文件名后缀正确,例如 "1.pdf " |
| recognize_formula | - | bool | - | 无需开启,大模型默认对版式类型文档进行公式识别 |
| analysis_chart | 否 | bool | True/False | 是否对统计图表进行解析 |
| parse_image_layout | - | bool | - | 无需开启,大模型默认解析文档中的所有图片 |
| language_type | - | string | - | 无需开启,大模型默认识别语种类型 |
请求代码示例
提示:使用示例代码前,请记得替换其中的示例Token、文档地址或Base64信息。
1import requests
2import os
3import base64
4
5
6def create_task(url, file_path, file_url):
7 """
8 Args:
9 url: string, 服务请求链接
10 file_path: 本地文件路径
11 file_url: 文件链接
12 Returns: 响应
13 """
14 # 文件请求
15 with open(file_path, "rb") as f:
16 file_data = base64.b64encode(f.read())
17 data = {
18 "file_data": file_data,
19 "file_url": file_url,
20 "file_name": os.path.basename(file_path)
21 }
22
23 # 文档切分参数,非必传
24 # return_doc_chunks = json.dumps({"switch": True, "chunk_size": -1})
25 # data["return_doc_chunks"] = return_doc_chunks
26
27 headers = {'Content-Type': 'application/x-www-form-urlencoded'}
28
29 response = requests.post(url, headers=headers, data=data)
30 return response
31
32if __name__ == '__main__':
33 request_host = "https://aip.baidubce.com/rest/2.0/brain/online/v2/paddle-vl-parser/task?" \
34 "access_token={token}"
35 file_path = "./test.pdf"
36 response = create_task(request_host, file_path, "")
37 print(response.json())
返回说明
返回参数
| 字段 | 类型 | 说明 |
|---|---|---|
| log_id | uint64 | 唯一的log id,用于问题定位 |
| error_code | int | 错误码 |
| error_msg | string | 错误描述信息 |
| result | dict | 返回的结果列表 |
| + task_id | string | 该请求生成的task_id,后续使用该task_id获取审查结果 |
返回示例
成功返回示例:
1{
2 "error_code": 0,
3 "error_msg": "",
4 "log_id": "10138598131137362685273505665433",
5 "result": {
6 "task_id": "task-3zy9Bg8CHt1M4pPOcX2q5bg28j26801S"
7 }
8}
失败返回示例(详细的错误码说明见API文档-错误码):
1{
2 "error_code": 282003,
3 "error_msg": "missing parameters",
4 "log_id": "37507631033585544507983253924141",
5 "result": "null"
6}
获取结果接口
请求说明
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/brain/online/v2/paddle-vl-parser/task/query
URL参数:
| 参数 | 值 |
|---|---|
| access_token | 通过API Key和Secret Key获取的access_token,参考“Access Token获取” |
Header如下:
| 参数 | 值 |
|---|---|
| Content-Type | application/x-www-form-urlencoded |
Body中放置请求参数,参数详情如下:
请求参数
| 参数 | 是否必选 | 类型 | 说明 |
|---|---|---|---|
| task_id | 是 | string | 发送提交请求时返回的task_id |
请求代码示例
提示:使用示例代码前,请记得替换其中的示例Token、task_id。
1import requests
2
3def query_task(url, task_id):
4 """
5 Args:
6 url: string, 请求链接
7 task_id: string, task id
8 Returns: 响应
9 """
10 data = {
11 "task_id": task_id
12 }
13 headers = {'Content-Type': 'application/x-www-form-urlencoded'}
14 print(url)
15 response = requests.post(url, headers=headers, data=data)
16 return response
17
18
19if __name__ == '__main__':
20 # 需要替换为实际的任务id
21 task_id = "task_id"
22 # {access_token} 需要替换为实际调用鉴权接口获取的access_token
23 request_host = "https://aip.baidubce.com/rest/2.0/brain/online/v2/paddle-vl-parser/task/query?access_token={access_token}"
24 resp = query_task(request_host, task_id)
25 print(resp.json())
返回说明
返回参数
| 字段 | 类型 | 说明 |
|---|---|---|
| log_id | uint64 | 唯一的log id,用于问题定位 |
| error_code | int | 错误码 |
| error_msg | string | 错误描述信息 |
| result | dict | 返回的结果列表 |
| + task_id | string | 任务ID |
| + status | string | 任务状态,pending:排队中;processing:运行中;success:成功;failed:失败 |
| + task_error | string | 解析报错信息,包含任务失败、额度不够 |
| + markdown_url | string | 文档解析结果的markdown格式链接,链接有效期30天 |
| + parse_result_url | string | 文档解析结果的bos链接,链接有效期30天 |
可通过parse_result_url下载解析结果的JSON文件,parse_result_url的返回参数如下:
| 字段 | 类型 | 说明 |
|---|---|---|
| file_name | string | 文档名称 |
| file_id | string | 文档ID |
| + pages | list | 文件单页解析内容 |
| ++ page_id | string | 页码ID |
| ++ page_num | int | 页码数 |
| ++ text | string | 当前页的所有纯文字内容 |
| ++ layouts | list | 页面内容版式分析的结果 |
| +++ layout_id | string | layout ID,layout元素唯一标志,以"xxxxx-layout-{global_layout_index}"形式,global_layout_index为layout元素整个文档的全局索引 |
| +++ text | string | layout对应的文本内容。注:当type为table, image时该字段为空, 需要根据type和layout_id分别到tables, images字段里找到对应的内容 |
| +++ position | list | layout元素在页面中的位置,[x, y, w, h] box框,左上角和宽高 |
| +++ type | string | layout元素类型, 当前可取值: • abstract:摘要 • algorithm:算法 • aside_text:旁注文本 • chart:图表 • content:目录 • display_formula:公式 • doc_title:文档标题 • figure_title:图片标题 • footer:页脚 • footer_image:页脚图片 • footnote:脚注 • formula_number:公式编号 • header:页眉 • header_image:页眉图片 • image:图片 • inline_formula:行内公式 • number:页码 • paragraph_title:段落标题 • reference:参考文献 • reference_content:参考文献内容 • seal:印章 • table:表格 • text:文本 • vertical_text:竖排文本 |
| ++ tables | list | 页面表格解析结果 |
| +++ layout_id | string | layout ID,与layouts中的元素type为table的元素的layout ID对应 |
| +++ markdown | string | 表格内容的markdown形式 |
| +++ position | list | 边框数据 「x, y, w, h」(x, y)为坐标点坐标,w为box宽度,h为box高度(以页面坐标为原点),版式格式时有效 |
| +++ cells | list | 单元格的内嵌版面信息,layout类型为表格时有值 |
| +++ matrix | list | 二位数组 表示表格内布局位置信息,每个元素对应cells列表中元素的索引 |
| ++ images | list | 页面中图片解析结果 |
| +++ layout_id | string | layout ID,与layouts中的元素type为image的元素的layout ID对应 |
| +++ position | list | 边框数据 「x, y, w, h」(x, y)为坐标点坐标,w为box宽度,h为box高度(以页面坐标为原点),版式格式时有效 |
| +++ data_url | string | 图片存储链接 |
| +++ image_description | string | 对统计图表进行内容解析和描述,输出结果为json字符串,可通过json.loads结构化为json格式 |
| ++ meta | dict | 页面元信息 |
| +++ page_width | int | 页面宽度 |
| +++ page_height | int | 页面高度 |
表格解析结构说明
以下图为例:

1{
2# cells列表包含14个元素,matrix中的每个数字表示一个单元格在cells列表中的索引。
3 "cells": [
4 {"layout_id": "layout-xxxx",
5 "position": [90, 376, 21, 10],
6 "text": "序号"
7 ...
8 }, # ... 其他单元格信息
9 ],
10 "matrix": [
11 [0, 1, 2],
12 [3, 4, 5],
13 [6, 7, 8],
14 [9, 10, 11],
15 [12, 12, 13],
16 [12, 12, 14]
17
18}
返回示例
成功返回示例:
1{
2 "log_id": "23596597899286921761579365582373",
3 "error_code": 0,
4 "error_msg": "",
5 "result":
6 {
7 "task_id": "task-UnvGsgbYZp9pS3BZRHn11ifzjNvKzTgf",
8 "status": "success",
9 "task_error": null,
10 "markdown_url": "https:xxxxxxxxxxxxxxxxxxx",
11 "parse_result_url": "https:xxxxxxxxxxxxxxxxxxx"
12 }
13}
解析结果示例:
1{
2 "file_name": "示例文件1(文字+表格)更新-改-1.pdf",
3 "file_id": "file-u9kVDu6dtwMyNrizbejMlF8A852aJLm2",
4 "pages": [
5 {
6 "page_id": "2aJLm2-page-0",
7 "page_num": 0,
8 "text": "买卖合同\n甲、乙双方根据《中华人民共和国合同法》及其它相关法律、法规的规定,本着平等、自愿、互利的原则,经友好协商,订立本合同,以资共同信守:\n1.合同标的物信息\n| 序号 | 商品名称 | 产品简称 | 单价 | 数量 | 总价 | 税率 | 备注 |\n| --- | --- | --- | --- | --- | --- | --- | --- |\n| 1 | 软件-AI | 中台内网-推理平台+训练平台 | 95,000 | 1 | 905,000 | 13% | 第一单元 |\n| 2 | 硬件【A】 | 服务器 | 30,250 | 37 | 1,11950 | 13% | 第一单元 |\n\n本合同一式【2】份,经双方代表签字盖章生效。甲乙双方各执【3】份,具有同等法律效力。\n1 \n",
9 "layouts": [
10 {
11 "layout_id": "2aJLm2-layout-1",
12 "text": "买卖合同",
13 "position": [
14 263,
15 109,
16 103,
17 28
18 ],
19 "type": "title"
20 ]
21 },
22 {
23 "layout_id": "2aJLm2-layout-2",
24 "text": "甲、乙双方根据《中华人民共和国合同法》及其它相关法律、法规的规定,本着平等、自愿、互利的原则,经友好协商,订立本合同,以资共同信守:",
25 "position": [
26 84,
27 160,
28 444,
29 31
30 ],
31 "type": "text"
32 },
33 {
34 "layout_id": "2aJLm2-layout-3",
35 "text": "1.合同标的物信息",
36 "position": [
37 79,
38 206,
39 110,
40 14
41 ],
42 "type": "title"
43 },
44 {
45 "layout_id": "2aJLm2-layout-4",
46 "text": "",
47 "position": [
48 82,
49 224,
50 452,
51 97
52 ],
53 "type": "table"
54 },
55 {
56 "layout_id": "2aJLm2-layout-5",
57 "text": "本合同一式【2】份,经双方代表签字盖章生效。甲乙双方各执【3】份,具有同等法律效力。",
58 "position": [
59 79,
60 348,
61 456,
62 31
63 ],
64 "type": "text"
65 },
66 {
67 "layout_id": "2aJLm2-layout-6",
68 "text": "1",
69 "position": [
70 305,
71 745,
72 11,
73 12
74 ],
75 "type": "head_tail"
76 }
77 ],
78 "tables": [
79 {
80 "layout_id": "2aJLm2-layout-4",
81 "markdown": "| 序号 | 商品名称 | 产品简称 | 单价 | 数量 | 总价 | 税率 | 备注 |\n| --- | --- | --- | --- | --- | --- | --- | --- |\n| 1 | 软件-AI | 中台内网-推理平台+训练平台 | 95,000 | 1 | 905,000 | 13% | 第一单元 |\n| 2 | 硬件【A】 | 服务器 | 30,250 | 37 | 1,11950 | 13% | 第一单元 |\n",
82 "position": [
83 82,
84 224,
85 452,
86 97
87 ],
88 "cells": [
89 {
90 "layout_id": "2aJLm2-layout-4-0",
91 "text": "序号",
92 "type": "text"
93 },
94 {
95 "layout_id": "2aJLm2-layout-4-1",
96 "text": "商品名称",
97 "type": "text"
98 },
99 {
100 "layout_id": "2aJLm2-layout-4-2",
101 "text": "产品简称"
102 "type": "text"
103 },
104 {
105 "layout_id": "2aJLm2-layout-4-3",
106 "text": "单价"
107 "type": "text"
108 },
109 {
110 "layout_id": "2aJLm2-layout-4-4",
111 "text": "数量"
112 "type": "text"
113 },
114 {
115 "layout_id": "2aJLm2-layout-4-5",
116 "text": "总价",
117 "type": "text"
118 },
119 {
120 "layout_id": "2aJLm2-layout-4-6",
121 "text": "税率",
122 "type": "text"
123 },
124 {
125 "layout_id": "2aJLm2-layout-4-7",
126 "text": "备注",
127 "type": "text"
128 },
129 {
130 "layout_id": "2aJLm2-layout-4-8",
131 "text": "1",
132 "type": "text"
133 },
134 {
135 "layout_id": "2aJLm2-layout-4-9",
136 "text": "软件-AI ",
137 "type": "text"
138 },
139 {
140 "layout_id": "2aJLm2-layout-4-10",
141 "text": "中台内网-推理平台+训练平台",
142 "type": "text"
143 },
144 {
145 "layout_id": "2aJLm2-layout-4-11",
146 "text": "95,000",
147 "type": "text"
148 },
149 {
150 "layout_id": "2aJLm2-layout-4-12",
151 "text": "1",
152 "type": "text"
153 },
154 {
155 "layout_id": "2aJLm2-layout-4-13",
156 "text": "905,000",
157 "type": "text"
158 },
159 {
160 "layout_id": "2aJLm2-layout-4-14",
161 "text": "13% ",
162 "type": "text"
163 },
164 {
165 "layout_id": "2aJLm2-layout-4-15",
166 "text": "第一单元",
167 "type": "text"
168 },
169 {
170 "layout_id": "2aJLm2-layout-4-16",
171 "text": "2",
172 "type": "text"
173 },
174 {
175 "layout_id": "2aJLm2-layout-4-17",
176 "text": "硬件【A】",
177 "type": "text"
178 },
179 {
180 "layout_id": "2aJLm2-layout-4-18",
181 "text": "服务器",
182 "type": "text"
183 },
184 {
185 "layout_id": "2aJLm2-layout-4-19",
186 "text": "30,250",
187 "type": "text"
188 },
189 {
190 "layout_id": "2aJLm2-layout-4-20",
191 "text": "37",
192 "type": "text"
193 },
194 {
195 "layout_id": "2aJLm2-layout-4-21",
196 "text": "1,11950",
197 "type": "text"
198 },
199 {
200 "layout_id": "2aJLm2-layout-4-22",
201 "text": "13% ",
202 "type": "text"
203 }
204 ],
205 "matrix": [
206 [
207 0,
208 1,
209 2,
210 3,
211 4,
212 5,
213 6,
214 7
215 ],
216 [
217 8,
218 9,
219 10,
220 11,
221 12,
222 13,
223 14,
224 15
225 ],
226 [
227 16,
228 17,
229 18,
230 19,
231 20,
232 21,
233 22,
234 15
235 ]
236 ]
237 }
238 ],
239 "images": [
240 {
241 "layout_id": "Kr9RM7-layout-10",
242 "position":
243 [
244 90,
245 549,
246 422,
247 221
248 ],
249 "data_url": " "
250 }
251 ],
252 "meta": {
253 "page_width": 612,
254 "page_height": 792
255 }
256 ]
257}
失败返回示例(详细的错误码说明见API文档-错误码):
1 {"log_id": "13665091038742503867108513247608",
2 "error_code": "282007",
3 "error_msg": "task not exist, please check task id",
4 "result": "null"}
