文档解析
curl --request POST \
--url https://api.textin.com/ai/service/v1/pdf_to_markdown \
--header 'Content-Type: application/octet-stream' \
--header 'x-ti-app-id: <api-key>' \
--header 'x-ti-secret-code: <api-key>'import requests
url = "https://api.textin.com/ai/service/v1/pdf_to_markdown"
headers = {
"x-ti-app-id": "<api-key>",
"x-ti-secret-code": "<api-key>",
"Content-Type": "application/octet-stream"
}
response = requests.post(url, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-ti-app-id': '<api-key>',
'x-ti-secret-code': '<api-key>',
'Content-Type': 'application/octet-stream'
}
};
fetch('https://api.textin.com/ai/service/v1/pdf_to_markdown', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.textin.com/ai/service/v1/pdf_to_markdown",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Content-Type: application/octet-stream",
"x-ti-app-id: <api-key>",
"x-ti-secret-code: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.textin.com/ai/service/v1/pdf_to_markdown"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("x-ti-app-id", "<api-key>")
req.Header.Add("x-ti-secret-code", "<api-key>")
req.Header.Add("Content-Type", "application/octet-stream")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.textin.com/ai/service/v1/pdf_to_markdown")
.header("x-ti-app-id", "<api-key>")
.header("x-ti-secret-code", "<api-key>")
.header("Content-Type", "application/octet-stream")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.textin.com/ai/service/v1/pdf_to_markdown")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-ti-app-id"] = '<api-key>'
request["x-ti-secret-code"] = '<api-key>'
request["Content-Type"] = 'application/octet-stream'
response = http.request(request)
puts response.read_body{
"code": 200,
"message": "success",
"result": {
"markdown": "# hello markdown",
"detail": [
{
"page_id": 1,
"paragraph_id": 123,
"outline_level": -1,
"text": "hello markdown",
"position": [
217,
390,
1336,
390,
1336,
460,
217,
460
],
"content": 0,
"type": "paragraph",
"origin_position": [
217,
390,
1336,
390,
1336,
460,
217,
460
],
"sub_type": "catalog",
"image_url": "<string>",
"tags": [
"formula",
"handwritten"
],
"caption_id": {
"page_id": 123,
"paragraph_id": 123
},
"cells": [
{
"row": 123,
"col": 123,
"row_span": 123,
"col_span": 123,
"position": [
10,
10,
100,
10,
100,
50,
10,
50
],
"origin_position": [
123
],
"text": "<string>",
"type": "<string>"
}
],
"split_section_page_ids": [
1,
2,
3
],
"split_section_positions": [
[
0,
0,
100,
100,
100,
200,
0,
200
],
[
0,
0,
100,
100,
100,
200,
0,
200
],
[
0,
0,
100,
100,
100,
200,
0,
200
]
],
"stamp": {
"value": "<string>",
"stamp_shape": "<string>",
"type": "<string>",
"color": "<string>"
}
}
],
"pages": [
{
"status": "success",
"page_id": 0,
"durations": 612.5,
"image_id": "90u12adcad08r2",
"origin_image_id": "90u12adcad08r2",
"base64": "<string>",
"origin_base64": "<string>",
"width": 123,
"height": 123,
"angle": 123,
"content": [
{
"id": 123,
"type": "line",
"text": "<string>",
"pos": [
123
],
"angle": 0,
"origin_position": [
123
],
"sub_type": "handwriting",
"direction": 123,
"score": 0.5,
"char_pos": [
[
123
]
]
}
],
"raw_ocr": [
{
"text": "这是一个例子。",
"score": 0.99,
"type": "text",
"position": [
10,
10,
100,
10,
100,
50,
10,
50
],
"angle": 123,
"direction": 1,
"handwritten": 1,
"char_scores": [
0.99,
0.98,
0.95,
0.95,
0.99,
0.93,
0.87
],
"char_centers": [
[
20,
10
],
[
30,
10
],
[
40,
10
],
[
50,
10
],
[
60,
10
],
[
70,
10
],
[
80,
10
]
],
"char_positions": [
[
18,
8,
22,
8,
22,
12,
18,
12
],
[
28,
88,
32,
8,
32,
12,
28,
12
],
[
38,
88,
42,
8,
42,
12,
38,
12
],
[
48,
88,
52,
8,
52,
12,
48,
12
],
[
58,
88,
62,
8,
62,
12,
58,
12
],
[
68,
88,
72,
8,
72,
12,
68,
12
],
[
78,
88,
82,
8,
82,
12,
78,
12
]
],
"char_candidates": [
[
"这"
],
[
"是"
],
[
"一",
"-"
],
[
"个"
],
[
"例"
],
[
"子"
],
[
"。",
"O"
]
],
"char_candidates_score": [
[
0.99
],
[
0.99
],
[
0.95,
0.05
],
[
0.99
],
[
0.99
],
[
0.99
],
[
0.89,
0.11
]
]
}
],
"structured": [
{
"type": "textblock",
"pos": [
123
],
"content": [
0,
1,
2
],
"origin_position": [
123
],
"sub_type": "text",
"continue": true,
"next_page_id": 2,
"next_para_id": 1,
"text": "<string>",
"outline_level": -1
}
]
}
],
"catalog": {
"toc": [
[
{
"hierarchy": 2,
"title": "1.公司简介和主要财务指标",
"page_id": 3,
"pos": [
10,
10,
100,
10,
100,
50,
10,
50
]
},
{
"hierarchy": 3,
"title": "1.1 公司简介",
"page_id": 4,
"pos": [
10,
10,
100,
10,
100,
50,
10,
50
]
}
]
]
},
"total_page_number": 10,
"valid_page_number": 3,
"excel_base64": "",
"success_count": 1,
"elements": [
{
"element_id": "",
"type": "NarrativeText",
"text": "xParse 是一个端到端文档处理 AI 基础设施",
"metadata": {
"page_image_url": "https://web-api.textin.com/ocr_image/external/01a91572ca81092c.jpg",
"angle": 0,
"page_number": 1,
"page_width": 600,
"page_height": 800,
"coordinates": [
0.182212,
0.231623,
0.671714,
0.231633,
0.671711,
0.273233,
0.182244,
0.273255
],
"is_continue": false,
"category_depth": -1,
"parent_id": "",
"original_image_url": "",
"sub_type": "stamp",
"image_url": "https://web-api.textin.com/ocr_image/external/e47f8aed69ccabce.jpg",
"image_base64": ""
}
}
]
},
"version": "2.1.0",
"duration": 999,
"metrics": [
{
"page_image_width": 1024,
"page_image_height": 768,
"durations": 123,
"status": "<string>",
"page_id": 123,
"angle": 90,
"dpi": 72,
"image_id": "<string>"
}
]
}智能文档解析
文档解析
上传图片/pdf/word/html/excel/ppt/txt,进行版面检测,文字识别,表格识别,版面分析等操作,并生成markdown文档及结构化数据
快速调试:请参考Postman调试教程或Apifox调试教程
POST
/
ai
/
service
/
v1
/
pdf_to_markdown
文档解析
curl --request POST \
--url https://api.textin.com/ai/service/v1/pdf_to_markdown \
--header 'Content-Type: application/octet-stream' \
--header 'x-ti-app-id: <api-key>' \
--header 'x-ti-secret-code: <api-key>'import requests
url = "https://api.textin.com/ai/service/v1/pdf_to_markdown"
headers = {
"x-ti-app-id": "<api-key>",
"x-ti-secret-code": "<api-key>",
"Content-Type": "application/octet-stream"
}
response = requests.post(url, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-ti-app-id': '<api-key>',
'x-ti-secret-code': '<api-key>',
'Content-Type': 'application/octet-stream'
}
};
fetch('https://api.textin.com/ai/service/v1/pdf_to_markdown', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.textin.com/ai/service/v1/pdf_to_markdown",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Content-Type: application/octet-stream",
"x-ti-app-id: <api-key>",
"x-ti-secret-code: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.textin.com/ai/service/v1/pdf_to_markdown"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("x-ti-app-id", "<api-key>")
req.Header.Add("x-ti-secret-code", "<api-key>")
req.Header.Add("Content-Type", "application/octet-stream")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.textin.com/ai/service/v1/pdf_to_markdown")
.header("x-ti-app-id", "<api-key>")
.header("x-ti-secret-code", "<api-key>")
.header("Content-Type", "application/octet-stream")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.textin.com/ai/service/v1/pdf_to_markdown")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-ti-app-id"] = '<api-key>'
request["x-ti-secret-code"] = '<api-key>'
request["Content-Type"] = 'application/octet-stream'
response = http.request(request)
puts response.read_body{
"code": 200,
"message": "success",
"result": {
"markdown": "# hello markdown",
"detail": [
{
"page_id": 1,
"paragraph_id": 123,
"outline_level": -1,
"text": "hello markdown",
"position": [
217,
390,
1336,
390,
1336,
460,
217,
460
],
"content": 0,
"type": "paragraph",
"origin_position": [
217,
390,
1336,
390,
1336,
460,
217,
460
],
"sub_type": "catalog",
"image_url": "<string>",
"tags": [
"formula",
"handwritten"
],
"caption_id": {
"page_id": 123,
"paragraph_id": 123
},
"cells": [
{
"row": 123,
"col": 123,
"row_span": 123,
"col_span": 123,
"position": [
10,
10,
100,
10,
100,
50,
10,
50
],
"origin_position": [
123
],
"text": "<string>",
"type": "<string>"
}
],
"split_section_page_ids": [
1,
2,
3
],
"split_section_positions": [
[
0,
0,
100,
100,
100,
200,
0,
200
],
[
0,
0,
100,
100,
100,
200,
0,
200
],
[
0,
0,
100,
100,
100,
200,
0,
200
]
],
"stamp": {
"value": "<string>",
"stamp_shape": "<string>",
"type": "<string>",
"color": "<string>"
}
}
],
"pages": [
{
"status": "success",
"page_id": 0,
"durations": 612.5,
"image_id": "90u12adcad08r2",
"origin_image_id": "90u12adcad08r2",
"base64": "<string>",
"origin_base64": "<string>",
"width": 123,
"height": 123,
"angle": 123,
"content": [
{
"id": 123,
"type": "line",
"text": "<string>",
"pos": [
123
],
"angle": 0,
"origin_position": [
123
],
"sub_type": "handwriting",
"direction": 123,
"score": 0.5,
"char_pos": [
[
123
]
]
}
],
"raw_ocr": [
{
"text": "这是一个例子。",
"score": 0.99,
"type": "text",
"position": [
10,
10,
100,
10,
100,
50,
10,
50
],
"angle": 123,
"direction": 1,
"handwritten": 1,
"char_scores": [
0.99,
0.98,
0.95,
0.95,
0.99,
0.93,
0.87
],
"char_centers": [
[
20,
10
],
[
30,
10
],
[
40,
10
],
[
50,
10
],
[
60,
10
],
[
70,
10
],
[
80,
10
]
],
"char_positions": [
[
18,
8,
22,
8,
22,
12,
18,
12
],
[
28,
88,
32,
8,
32,
12,
28,
12
],
[
38,
88,
42,
8,
42,
12,
38,
12
],
[
48,
88,
52,
8,
52,
12,
48,
12
],
[
58,
88,
62,
8,
62,
12,
58,
12
],
[
68,
88,
72,
8,
72,
12,
68,
12
],
[
78,
88,
82,
8,
82,
12,
78,
12
]
],
"char_candidates": [
[
"这"
],
[
"是"
],
[
"一",
"-"
],
[
"个"
],
[
"例"
],
[
"子"
],
[
"。",
"O"
]
],
"char_candidates_score": [
[
0.99
],
[
0.99
],
[
0.95,
0.05
],
[
0.99
],
[
0.99
],
[
0.99
],
[
0.89,
0.11
]
]
}
],
"structured": [
{
"type": "textblock",
"pos": [
123
],
"content": [
0,
1,
2
],
"origin_position": [
123
],
"sub_type": "text",
"continue": true,
"next_page_id": 2,
"next_para_id": 1,
"text": "<string>",
"outline_level": -1
}
]
}
],
"catalog": {
"toc": [
[
{
"hierarchy": 2,
"title": "1.公司简介和主要财务指标",
"page_id": 3,
"pos": [
10,
10,
100,
10,
100,
50,
10,
50
]
},
{
"hierarchy": 3,
"title": "1.1 公司简介",
"page_id": 4,
"pos": [
10,
10,
100,
10,
100,
50,
10,
50
]
}
]
]
},
"total_page_number": 10,
"valid_page_number": 3,
"excel_base64": "",
"success_count": 1,
"elements": [
{
"element_id": "",
"type": "NarrativeText",
"text": "xParse 是一个端到端文档处理 AI 基础设施",
"metadata": {
"page_image_url": "https://web-api.textin.com/ocr_image/external/01a91572ca81092c.jpg",
"angle": 0,
"page_number": 1,
"page_width": 600,
"page_height": 800,
"coordinates": [
0.182212,
0.231623,
0.671714,
0.231633,
0.671711,
0.273233,
0.182244,
0.273255
],
"is_continue": false,
"category_depth": -1,
"parent_id": "",
"original_image_url": "",
"sub_type": "stamp",
"image_url": "https://web-api.textin.com/ocr_image/external/e47f8aed69ccabce.jpg",
"image_base64": ""
}
}
]
},
"version": "2.1.0",
"duration": 999,
"metrics": [
{
"page_image_width": 1024,
"page_image_height": 768,
"durations": 123,
"status": "<string>",
"page_id": 123,
"angle": 90,
"dpi": 72,
"image_id": "<string>"
}
]
}Authorizations
请登录Textin后前往 "工作台-账号设置-开发者信息" 查看 x-ti-app-id
请登录Textin后前往 "工作台-账号设置-开发者信息" 查看 x-ti-secret-code
Query Parameters
Body
application/octet-streamtext/plain
支持以下两种请求格式:
-
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像素范围内。
-
Content-Type: text/plain
请求体为文本,内容为在线文件的URL链接(支持http以及https协议)。
- 在线文件大小不超过500M。
- 长宽比小于2的图片宽高需在20~20000像素范围内,其他图片的宽高需在20~10000像素范围内。
The body is of type file.
Response
200 - application/json
解析结果
返回markdown及结构化数据
状态码
- 200: Success
- 40101: x-ti-app-id 或 x-ti-secret-code 为空
- 40102: x-ti-app-id 或 x-ti-secret-code 无效,验证失败
- 40103: 客户端IP不在白名单
- 40003: 余额不足,请充值后再使用
- 40004: 参数错误,请查看技术文档,检查传参
- 40007: 机器人不存在或未发布
- 40008: 机器人未开通,请至市场开通后重试
- 40301: 图片类型不支持
- 40302: 上传文件大小不符,文件大小不超过 500M
- 40303: 文件类型不支持,接口会返回实际检测到的文件类型,如“当前文件类型为.gif”
- 40304: 图片尺寸不符,长宽比小于2的图片宽高需在20~20000像素范围内,其他图片的宽高需在20~10000像素范围内
- 40305: 识别文件未上传
- 40306: 请求频率(QPS)或页数速率(page_rate)超过限制
- 40422: 文件损坏(The file is corrupted.)
- 40423: PDF密码错误(Password required or incorrect password.)
- 40424: 页数设置超出文件范围(Page number out of range.)
- 40425: 文件格式不支持(The input file format is not supported.)
- 40427: DPI参数不在支持列表中(Input DPI is not in the allowed DPIs list(72,144,216).)
- 40428: word和ppt转pdf失败或者超时(Process office file failed.)
- 50207: 部分页面解析失败(Partial failed)
- 40400: 无效的请求链接,请检查链接是否正确
- 30203: 基础服务故障,请稍后重试
- 500: 服务器内部错误
Available options:
200, 40101, 40102, 40103, 40003, 40004, 40007, 40008, 40301, 40302, 40303, 40304, 40305, 40306, 40422, 40423, 40424, 40425, 40427, 40428, 50207, 40400, 30203, 500 Was this page helpful?

