
- File Converter
功能描述
pdf转markdown
上传图片/pdf/word/html/excel/ppt/txt,进行版面检测,文字识别,表格识别,版面分析等操作,并生成markdown文档
请求URL
https://api.textin.com/ai/service/v1/pdf_to_markdown
HTTP请求方法(Method)
HTTP POST
请求头说明(Request Headers)
请在HTTP请求中添加以下自定义标头(Header)。
header 名 | 值 |
---|---|
x-ti-app-id | 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-app-id |
x-ti-secret-code | 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-secret-code |
URL参数(Parameters)
URL参数指以{参数名}={参数值} 形式拼接到 URL 上的键值对。它以
?
开头,不同参数之间使用&
连接。形如?p1=v1&p2=v2
参数名 | 数据类型 | 是否必填 | 允许的值 | 描述 |
---|---|---|---|---|
pdf_pwd | string | 否 | 见描述 |
Password required when PDF is encrypted. Note: When encapsulating this interface in the frontend, password security protection should be implemented independently |
char_details | integer | 否 | 0, 1 |
When set to 1 or true, returns the char_pos field containing position information for each character. Default is off |
page_details | integer | 否 | 0, 1 |
When set to 1 or true, returns the pages field containing more detailed parsing results for each page. Default is on |
catalog_details | integer | 否 | 0, 1 |
When set to 1 or true, returns catalog details |
dpi | integer | 否 | 见描述 |
Coordinate reference for PDF documents, default is 144 dpi. When parse_mode=auto, default is dynamic, supports 72, 144, 216; When parse_mode=scan, default is 144, supports 72, 144, 216; |
page_start | integer | 否 | 见描述 |
When uploading a PDF, page_start indicates which page to start conversion from |
page_count | integer | 否 | 见描述 |
When uploading a PDF, page_count indicates the number of PDF pages to convert. Total pages must not exceed 1000 pages, default is 1000 pages |
apply_document_tree | integer | 否 | 0, 1 |
Whether to generate titles, default is 1 to generate titles
|
markdown_details | integer | 否 | 0, 1 |
Whether to generate markdown details, default is 1 to generate markdown details
|
table_flavor | string | 否 | md, html, none |
Table format in markdown, default is html to output tables in html syntax
|
get_image | string | 否 | none, page, objects, both |
Get images in markdown, default is none to return no images
|
image_output_type | string | 否 | default, base64str |
Specify the output type of image objects returned by the engine, default returns sub-image URLs and page image IDs
|
parse_mode | string | 否 | auto, scan |
PDF parsing mode, default is scan mode, processing only by text recognition. Images do not need to be set, all processed by text recognition mode.
|
get_excel | integer | 否 | 0, 1 |
Whether to return excel results, result field is excel_base64, default is 0 to not return
|
raw_ocr | integer | 否 | 0, 1 |
Whether to return full text recognition results, result field is raw_ocr. Default is 0 to not return. Does not return when page_details is 0 or false.
|
切边矫正(****联系商务获取参数名****) | integer | 否 | 0, 1 |
Whether to perform edge cropping correction, default is 0 to not perform edge cropping correction
|
去水印(****联系商务获取参数名****) | integer | 否 | 0, 1 |
Whether to perform watermark removal, default is 0 to not remove watermarks
|
图表识别(****联系商务获取参数名****) | integer | 否 | 0, 1 |
Whether to enable chart recognition, enabling chart recognition will output recognized charts in table format. Default is 0 to not perform chart recognition.
|
paratext_mode | string | 否 | annotation, body |
Display mode for non-body text content in markdown. Default is annotation. Non-body content includes headers, footers, and text in sub-images.
|
formula_level | integer | 否 | 0, 1, 2 |
Formula recognition level, default is 0 for full recognition.
|
apply_merge | integer | 否 | 0, 1 |
Whether to perform paragraph merging and table merging. Default is 1 to merge paragraphs and tables.
|
apply_image_analysis | integer | 否 | 0, 1 |
Use large models to analyze sub-images in documents. Analysis results are output in markdown format and replace the text recognition content of sub-images. Default is 0 to not perform image analysis.
|
请求体说明(Request Body)
支持以下两种请求格式
1. Content-Type: application/octet-stream
支持的文件格式:png, jpg, jpeg, pdf, bmp, tiff, webp, doc, docx, html, mhtml, xls, xlsx, csv, ppt, pptx, txt, ofd, rtf。如果是xls/xlsx/csv文件,每个sheet行数不能超过2000,列数不能超过100。如果是txt文件,文件大小不超过100k。
请注意,请求体的数据格式为本地文件的二进制流,非 FormData 或其他格式。文件大小不超过 500M,长宽比小于2的图片宽高需在20~20000像素范围内,其他图片的宽高需在20~10000像素范围内
2. Content-Type: text/plain
请求体的数据格式为文本,内容为在线文件的URL链接(支持http以及https协议)。在线文件大小不超过 500M,长宽比小于2的图片宽高需在20~20000像素范围内,其他图片的宽高需在20~10000像素范围内
响应体说明 (Response)
Content-Type: application/json
JSON结构说明如下:
说明:所有接口响应中均包含字段 x_request_id
(string类型),作为请求的唯一标识。
字段名 | 类型 | 描述 |
---|---|---|
code | integer | 错误码,详见“错误码说明” |
message | string |
错误信息 |
result | object | |
+ total_page_number | integer |
输入Pdf时, 返回文档的总页数 |
+ valid_page_number | integer |
记录本次解析成功的总页数 |
+ pages | array |
文档按照页为单位展开时, 存储每一页的详情和状态 (适用于PDF),部分信息跟metrics字段重复。为兼容旧接口,保留metrics信息。 |
++ status | string |
表示当前页的引擎输出状态,或者error_message |
++ page_id | number |
当前页码 (若为流式文件, 页码置为0) |
++ durations | number |
当前页总耗时 |
++ image_id | string |
当前页图片id (下载方式:https://api.textin.com/ocr_image/download?image_id=xxx ,需要在headers里添加appid和key)。当输入参数image_output_type=default且get_image=page/both时返回。
例如使用curl下载 |
++ origin_image_id | string |
切边或去水印前的原始页图片,仅当开启切边或去水印,image_output_type=default且get_image=page/both时返回。下载方式同image_id |
++ base64 | string |
当前页图片的base64字符串,当输入参数image_output_type=base64str且get_image=page/both时返回。 |
++ origin_base64 | string |
切边或去水印前的原始页图片base64字符串,仅当开启切边或去水印,image_output_type=base64str且get_image=page/both时返回 |
++ width | integer |
文档页宽度 |
++ height | integer |
文档页高度 |
++ angle | integer |
图像(中文字)的角度(当输入为图像时,默认为0, 可选值0, 90, 180, 270) |
++ content | array |
基础数据: 文字行, 图像中的其中一种,请参考textline和image的说明 |
++ raw_ocr | array |
当入参raw_ocr=1时返回,为文本行识别结果,不包含图片。和content里的textline区别为,raw_ocr为ocr输出的原始结果,textline为经过排版、合并、拆分等后处理的结果。 |
++ structured | array |
结构化数据, 为textblock, table, imageblock, footer, header, sidebar中的一种 |
+ detail | array |
markdown详细信息, 参考markdown_details的说明 |
++ page_id | integer |
当前段落所在页码 |
++ paragraph_id | integer |
当前段落id |
++ outline_level | integer |
标题级别: (最多支持5级标题) -1.正文 0.一级标题 1.二级标题 ... |
++ text | string |
文本 |
++ type | string |
类型, paragraph(段落类型,包括正文、标题、公式等文字信息)、image(图片类型)、table(表格类型) |
++ image_url | string |
当get_image = objects 时,返回图片的公共连接,图片默认保存30天,如需长久保存,请在有效期内下载图片并保存;或者使用image_output_type=base64str,图片以base64的方式返回 |
++ content | integer |
内容类型
|
++ position | array |
以长度为8的整型数组表示四边形,8个数两两一组为一个点的横纵坐标,分别是左上,右上,右下,左下。 当输入是PDF时, 此坐标是基于72dpi的;当输入是图片时,此坐标是原图里的坐标。 单位:像素 |
++ origin_position | array |
仅当打开切边时返回,表示该段落在原图中的坐标。格式同position。 |
++ 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 |
++ caption_id | object |
表格或图片的标题id |
+++ page_id | integer |
标题所在页码 |
+++ paragraph_id | integer |
标题所在段落id |
++ cells | array |
单元格数组, 仅在type为table时返回 |
+++ row | integer |
单元格行号 |
+++ col | integer |
单元格列号 |
+++ row_span | integer |
单元格行跨度,默认为1 |
+++ col_span | integer |
单元格列跨度,默认为1 |
+++ position | array |
单元格的四个角点坐标,依次left-top,right-top,right-bottom,left-bottom. |
+++ origin_position | array |
仅当打开切边时返回,表示该单元格在原图中的坐标。格式同position。 |
+++ text | string |
单元格文本内容 |
+++ type | string |
类型,固定为cell,表示单元格 |
++ split_section_page_ids | array |
当表格有合并时,记录合并前各个子表格所在的页的id,方便前端渲染 |
++ split_section_positions | array |
当表格有合并时,记录合并前各个子表格所在页的位置,方便前端渲染 |
++ stamp | object |
当sub_type为stamp时,返回印章识别结果 |
+++ value | string |
印章文本内容 |
+++ stamp_shape | string |
印章形状 |
+++ type | string |
印章类型 |
+++ color | string |
印章颜色 |
+ catalog | object |
描述目录树的结构 |
++ toc | array |
返回的table of contents |
+++ sub_type | string |
标题类型 text_title、 image_title、 table_title |
+++ hierarchy | integer |
标题层级, 1 是 1级标题, 2 是 2级标题,依次类推 |
+++ title | string |
标题内容 |
+++ page_id | integer |
标题所在页码 (最小页码为 1) |
+++ paragraph_id | integer |
标题所在段落id |
+++ pos | array |
该目录区域的四个角点坐标,依次left-top,right-top,right-bottom,left-bottom. |
+++ pos_list | array |
发生标题合并时,为合并前多个标题的坐标。未发生标题合并时,即为该标题的坐标 |
+ markdown | string |
markdown 正文字符串 |
+ excel_base64 | string |
excel的base64结果,仅当get_excel=1时返回。 |
version | string |
doc_restore 引擎版本号 |
duration | integer |
引擎耗时 (毫秒) |
metrics | array |
每一页的信息 |
+ page_image_width | integer |
当前段落所在页的图片宽或者pdf转成的图片宽 |
+ page_image_height | integer |
当前段落所在页的图片高或者pdf转成的图片高 |
+ dpi | integer |
当前pdf页转成图片所用的dpi |
+ durations | number |
当前页总耗时 |
+ status | string |
当前页状态 |
+ page_id | number |
当前页码 |
+ angle | integer |
图像角度, 定义0度为人类阅读文字的图像方向,称为正置图像, 本字段表示输入图像是正置图像进行顺时针若干角度的旋转所得。
|
+ image_id | string |
当前页图片id (下载方式:https://api.textin.com/ocr_image/download?image_id=xxx, 需要在headers里添加appid和key, 有效期30天) |
结构体说明
各类型返回的字段及字段定义说明如下:
textline
字段名 | 类型 | 描述 |
---|---|---|
id | integer |
数据id(页内唯一) |
type | string |
数据类型,line |
text | string |
文本行文字内容 |
angle | integer |
文本行文字方向。文本行方向是基于转正后的页面计算,即angle=0表示文本行方向和页面方向一致。 |
pos | array |
文本行四个角点坐标 |
origin_position | array |
仅当打开切边时返回,表示文本行在原图中的坐标。格式同pos。 |
sub_type | string |
子类型, 有handwriting, formula |
direction | integer |
文字方向, 默认为0. 0:横向文本; 1:竖向文本; 2:横向右往左文本(如阿拉伯语) |
score | number |
文本行内每个字符的置信度(仅当输入图像做ocr时) |
char_pos | array |
文本行内每个字符的坐标,每个item是一个由八个整数组成的数组,分别表示,左上,右上,右下,左下四个点的(x,y)坐标 |
image
字段名 | 类型 | 描述 |
---|---|---|
id | integer |
数据id |
type | string |
数据类型, image |
pos | array |
图像四个角点坐标 |
sub_type | string |
子类型, 包括stamp, chart, qrcode, barcode |
size | array |
图像大小[width, height] |
data | object |
图像内容 |
+ base64 | string |
图像文件(jpg, png)的base64字符串 |
+ region | array |
图像在页图像中的区域(四边形4个点坐标) |
+ path | string |
图像文件路径(如在zip包中的路径) |
stamp | object |
仅当sub_type为stamp时有值,为印章识别结果 |
+ value | string |
印章文本内容 |
+ stamp_shape | string |
印章形状 |
+ type | string |
印章类型 |
+ color | string |
印章颜色 |
imageblock
字段名 | 类型 | 描述 |
---|---|---|
type | string |
图像块类型, 值为 image |
pos | array |
文本行四个角点坐标 |
origin_position | array |
仅当打开切边时返回,表示该子图在原图中的坐标。格式同pos。 |
lines | array |
图像包含的文本行id, |
content | array |
图像资源数据id数组 |
caption_id | object |
图片的标题id |
+ page_id | integer |
标题所在页码 |
+ paragraph_id | integer |
标题所在段落id |
text | string |
子图片识别得到的文本内容 |
textblock
字段名 | 类型 | 描述 |
---|---|---|
type | string |
段落块类型, 固定为 textblock |
pos | array |
文本行四个角点 |
origin_position | array |
仅当打开切边时返回,表示该段落在原图中的坐标。格式同pos。 |
content | array |
段落块内文本行id数据组 |
sub_type | string |
段落块字类型,包括catalog(目录),text(正文普通文本),text_title(文本标题),image_title(图片标题),table_title(表格标题) |
continue | boolean |
段落块连续属性,用于判断完整的段落块是否被页面或栏分割,为true表示该段落块和下一个段落块连续(即两个段落块可合成一个逻辑段落块)。 |
next_page_id | integer |
当且仅当continue为true时有值。表示下一个段落块的page_id。 |
next_para_id | integer |
当且仅当continue为true时有值。表示下一个段落块的paragraph_id。 |
text | string |
段落块文本内容 |
outline_level | integer |
标题级别: (最多支持5级标题) -1.正文 0.一级标题 1.二级标题 ... |
table
字段名 | 类型 | 描述 |
---|---|---|
type | string |
表格块类型, 固定为table |
sub_type | string |
表格子属性,取值为bordered(有线表)或borderless(无线表),默认为bordered(即json中无该字段时,默认值为bordered) |
pos | array |
文本行四个角点坐标 |
origin_position | array |
仅当打开切边时返回,表示该表格在原图中的坐标。格式同pos。 |
rows | integer |
表格行数 |
cols | integer |
表格列数 |
columns_width | array |
表格列宽度列表 |
rows_height | array |
表格行高度列表 |
text | string |
表格文本内容,以html或md格式展示 |
continue | boolean |
当前表格与后一表格连续,用来判断一个表格是否被页面分割(如果 continue为true 且该表格位于本页结尾,该表格可与下一页开头表格组合为一个表格) |
caption_id | object |
表格的标题id |
+ page_id | integer |
标题所在页码 |
+ paragraph_id | integer |
标题所在段落id |
cells | array |
单元格数组 |
+ row | integer |
单元格行号 |
+ col | integer |
单元格列号 |
+ row_span | integer |
单元格行跨度,默认为1 |
+ col_span | integer |
单元格列跨度,默认为1 |
+ pos | array |
单元格的四个角点坐标,依次left-top,right-top,right-bottom,left-bottom. |
+ content | array |
单元格内容 |
footer
字段名 | 类型 | 描述 |
---|---|---|
type | string |
页脚块类型,固定为 footer |
pos | array |
文本行四个角点坐标 |
blocks | array |
footer段落内容,为textblock, imageblock, table中其中的一种 |
header
字段名 | 类型 | 描述 |
---|---|---|
type | string |
页眉块类型,固定为 header |
pos | array |
文本行四个角点坐标 |
blocks | array |
header段落内容,为textblock, imageblock, table中的其中一种 |
imagedata
字段名 | 类型 | 描述 |
---|---|---|
base64 | string |
图像文件(jpg, png)的base64字符串 |
region | array |
图像在页图像中的区域(四边形4个点坐标) |
path | string |
图像文件路径(如在zip包中的路径) |
JSON结构示例
{
"code": 200,
"message": "success",
"result": {
"total_page_number": 10,
"document_type": "pdf",
"valid_page_number": 3,
"paragraph_number": 18,
"character_number": 3280,
"pages": [
{
"status": "success",
"page_id": 0,
"durations": 612.5,
"image_id": "90u12adcad08r2",
"width": 0,
"height": 0,
"angle": 0,
"content": [
{
"id": 0,
"type": "line",
"text": "string",
"angle": 0,
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"sub_type": "handwriting",
"direction": 0,
"score": 1,
"char_pos": [
[
0,
0,
0,
0,
0,
0,
0,
0
]
],
"char_cand": [
[
"string"
]
],
"char_cand_score": [
[
1
]
]
},
{
"id": 0,
"type": "image",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"sub_type": "string",
"stamp_type": "公章",
"stamp_shape": "园章",
"stamp_color": "红色",
"size": [
0,
0
],
"data": {
"base64": "string",
"region": [
0,
0,
0,
0,
0,
0,
0,
0
],
"path": "string"
}
}
],
"structured": [
{
"type": "textblock",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"content": [
0,
1,
2
],
"sub_type": "title",
"continue": true
},
{
"type": "table",
"sub_type": "bordered",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"rows": 0,
"cols": 0,
"columns_width": [
0
],
"rows_height": [
0
],
"continue": true,
"cells": [
{
"row": 0,
"col": 0,
"row_span": 0,
"col_span": 0,
"pos": [
10,
10,
100,
10,
100,
50,
10,
50
],
"content": [
{
"type": "textblock",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"content": [
0,
1,
2
],
"sub_type": "title",
"continue": true
},
{
"type": "image",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"lines": [
1
],
"zorder": 0,
"content": [
0
]
}
]
}
]
},
{
"type": "image",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"lines": [
1
],
"zorder": 0,
"content": [
0
]
},
{
"type": "footer",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"blocks": [
{
"type": "textblock",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"content": [
0,
1,
2
],
"sub_type": "title",
"continue": true
},
{
"type": "image",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"lines": [
1
],
"zorder": 0,
"content": [
0
]
},
{
"type": "table",
"sub_type": "bordered",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"rows": 0,
"cols": 0,
"columns_width": [
0
],
"rows_height": [
0
],
"continue": true,
"cells": [
{
"row": 0,
"col": 0,
"row_span": 0,
"col_span": 0,
"pos": [
10,
10,
100,
10,
100,
50,
10,
50
],
"content": [
{
"type": "textblock",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"content": [
0,
1,
2
],
"sub_type": "title",
"continue": true
},
{
"type": "image",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"lines": [
1
],
"zorder": 0,
"content": [
0
]
}
]
}
]
}
]
},
{
"type": "header",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"blocks": [
{
"type": "textblock",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"content": [
0,
1,
2
],
"sub_type": "title",
"continue": true
},
{
"type": "image",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"lines": [
1
],
"zorder": 0,
"content": [
0
]
},
{
"type": "table",
"sub_type": "bordered",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"rows": 0,
"cols": 0,
"columns_width": [
0
],
"rows_height": [
0
],
"continue": true,
"cells": [
{
"row": 0,
"col": 0,
"row_span": 0,
"col_span": 0,
"pos": [
10,
10,
100,
10,
100,
50,
10,
50
],
"content": [
{
"type": "textblock",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"content": [
0,
1,
2
],
"sub_type": "title",
"continue": true
},
{
"type": "image",
"pos": [
0,
0,
0,
0,
0,
0,
0,
0
],
"lines": [
1
],
"zorder": 0,
"content": [
0
]
}
]
}
]
}
]
}
]
}
],
"detail": [
{
"page_id": 1,
"paragraph_id": 0,
"outline_level": -1,
"text": "hello markdown",
"type": "paragraph",
"image_url": "string",
"content": 0,
"position": [
217,
390,
1336,
390,
1336,
460,
217,
460
]
}
],
"markdown": "# hello markdown"
},
"version": "2.1.0",
"duration": 999,
"metrics": [
{
"page_image_width": 1024,
"page_image_height": 768,
"dpi": 72,
"durations": 0,
"status": "string",
"page_id": 0,
"angle": 90,
"image_id": "string"
}
]
}