---
title: "文档解析"
method: POST
path: "/ai/service/v1/pdf_to_markdown"
tags: ["文档解析"]
---

# 文档解析

`POST /ai/service/v1/pdf_to_markdown`

上传图片/pdf/word/html/excel/ppt/txt，进行版面检测，文字识别，表格识别，版面分析等操作，并生成markdown文档及结构化数据

快速调试：请参考[Postman调试教程](/xparse/parse-debug-postman)或[Apifox调试教程](/xparse/parse-debug-apifox)

## Query parameters

- `parse_mode` 'auto' | 'scan' | 'lite' | 'parse'
- `pdf_pwd` string
- `page_start` integer
- `page_count` integer
- `dpi` 72 | 144 | 216
- `apply_document_tree` 0 | 1
- `table_flavor` 'md' | 'html' | 'none'
- `get_image` 'none' | 'page' | 'objects' | 'both'
- `image_output_type` 'base64str' | 'default'
- `paratext_mode` 'none' | 'annotation' | 'body'
- `formula_level` 0 | 1 | 2
- `underline_level` 0 | 1 | 2
- `apply_merge` 0 | 1 — 是否进行段落合并和表格合并。默认为1，合并段落和表格。 - 0 不合并 - 1 合并
- `apply_image_analysis` 0 | 1
- `markdown_details` 0 | 1
- `page_details` 0 | 1
- `raw_ocr` 0 | 1
- `char_details` 0 | 1
- `catalog_details` 0 | 1
- `get_excel` 0 | 1
- `crop_dewarp` 0 | 1
- `remove_watermark` 0 | 1
- `apply_chart` 0 | 1

## Response `200`

解析结果

- object — 返回markdown及结构化数据
  - `code` 200 | 40101 | 40102 | 40004 | 500, required — 状态码 - 200: Success - 40101: x-ti-app-id 或 x-ti-secret-code 为空 - 40102: x-ti-app-id 或 x-ti-secret-code 无效，验证失败 - 40004: 参数错误，请查看技术文档，检查传参 - 500: 服务器内部错误 更多详细错误信息参考[错误码说明](/xparse/v1/parse-response#常见错误码)。
  - `message` string, required — 错误信息
  - `result` object, required
    - `markdown` string, required — 完整 markdown 正文文本。
    - `detail` MarkdownDetails[] — markdown分块后各类型元素详细信息， 入参markdown_details=1时返回（1式返回（默认））
      - `page_id` integer, required — 当前元素所在页码，例如”1”
      - `paragraph_id` integer, required — 当前元素id
      - `outline_level` -1 | 0 | 1 | 2 | 3 | 4, required — 标题级别(最多支持5级标题) -1表示正文，0表示一级标题，1表示二级标题 …
      - `text` string, required — 文本
      - `position` integer[], required — 以长度为8的整型数组表示四边形，8个数两两一组为一个点的横纵坐标，分别是左上，右上，右下，左下。 当输入是PDF时, 此坐标是基于72dpi的;当输入是图片时，此坐标是原图里的坐标。 单位：像素
      - `origin_position` integer[] — 仅当打开切边时返回，表示该段落在原图中的坐标。格式同position。
      - `content` integer, required — 内容类型 - 0 正文(段落、图片、表格) - 1 非正文(页眉、页脚、侧边栏)
      - `type` 'image' | 'table' | 'paragraph', required — 类型, paragraph（段落类型，包括正文、标题、公式等文字信息）、image（图片类型）、table（表格类型）
      - `sub_type` 'catalog' | 'header' | 'footer' | 'sidebar' | 'text' | 'text_title' | 'image_title' | 'table_title' | 'stamp' | 'chart' | 'qrcode' | 'barcode' | 'bordered' | 'borderless' — 子类型。当type为paragraph时，取值范围为catalog(目录),header(页眉),footer(页脚),sidebar(侧边栏),text(正文普通文本),text_title(文本标题),image_title(图片标题),table_title(表格标题)；当type是image时，取值范围为stamp(印章),chart(图表),qrcode(二维码),barcode(条形码)；当type为table时，取值范围为bordered(有线表), borderless(无线表)。
      - `image_url` string — 图片链接，仅在type为image时返回，当get_image = objects 时，返回图片的公共连接,图片默认保存30天，如需长久保存，请在有效期内下载图片并保存;或者使用image_output_type=base64str,图片以base64的方式返回
      - `tags` string[] — 表示段落内是否存在特殊文本，类型包括公式formula和手写体handwritten
      - `caption_id` object — 表格或图片的标题id，仅在type为image或table时返回
        - `page_id` integer — 标题所在页码
        - `paragraph_id` integer — 标题所在段落id
      - `cells` object[] — 单元格数组, 仅在type为table时返回
        - `row` integer, required — 单元格行号
        - `col` integer, required — 单元格列号
        - `row_span` integer — 单元格行跨度,默认为1
        - `col_span` integer — 单元格列跨度,默认为1
        - `position` integer[] — 单元格的四个角点坐标，依次为左上，右上，右下，左下
        - `origin_position` integer[] — 受URL参数切边矫正或去水印影响，仅当打开切边或去水印时返回，表示该单元格在原图中的坐标，格式同position。
        - `text` string — 单元格文本内容
        - `type` string — 类型，固定为cell，表示单元格
      - `split_section_page_ids` integer[] — 当表格/段落有合并时，记录合并前各个子表格/段落所在的页的id
      - `split_section_positions` array[] — 当表格/段落有合并时，记录合并前各个子表格/段落所在页的位置，位置所属的页码与split_section_page_ids按索引一一对应，如split_section_positions[2]所属的页码为split_section_page_ids[2]
        - integer[]
      - `stamp` object — 当sub_type为stamp时，返回印章识别结果
        - `value` string — 印章文本内容
        - `stamp_shape` string — 印章形状
        - `type` string — 印章类型
        - `color` string — 印章颜色
    - `pages` PagesDetail[] — 文档按页为单位展开时，存储每一页的详情和状态（适用于PDF），部分信息与metrics字段重复。入参page_details=1式返回（默认）
      - `status` string — 表示当前页的引擎输出状态，或者error_message
      - `page_id` number — 当前页码 (若为流式文件, 页码置为0)
      - `durations` number, float — 当前页总耗时
      - `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下载\ curl 'https://api.textin.com/ocr_image/download?image_id=xxx' \ --header 'x-ti-app-id: c81f*************************e9ff' \ --header 'x-ti-secret-code: 5508********************1c17'
      - `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` union[] — 基础数据: 文字行, 图像中的其中一种，请参考textline和image的说明
        - union
          - Textline — 文本行数据
            - `id` integer, required — 数据id(页内唯一)
            - `type` string, required — 数据类型,line
            - `text` string, required — 文本行文字内容, 当sub_type=stamp时， text为印章上的文字.
            - `angle` 0 | 90 | 180 | 270 — 文本行文字方向。文本行方向是基于转正后的页面计算，即angle=0表示文本行方向和页面方向一致。
            - `pos` integer[], required — 文本行四个角点坐标
            - `origin_position` integer[] — 仅当打开切边时返回，表示文本行在原图中的坐标。格式同pos。
            - `sub_type` 'handwriting' | 'formula' — 子类型, 有handwriting, formula
            - `direction` integer — 文字方向, 默认为0. 0:横向文本; 1:竖向文本; 2:横向右往左文本（如阿拉伯语）
            - `score` number — 文本行内每个字符的置信度(仅当输入图像做ocr时)
            - `char_pos` array[] — 文本行内每个字符的坐标,每个item是一个由八个整数组成的数组，分别表示，左上，右上，右下，左下四个点的（x,y)坐标
              - …
          - Image — 图像数据
            - `id` integer, required — 数据id
            - `type` string, required — 数据类型, image
            - `pos` integer[], required — 图像四个角点坐标
            - `sub_type` string — 子类型, 包括stamp, chart, qrcode, barcode
            - `size` integer[] — 图像大小[width, height]
            - `data` Imagedata, required — 图像数据, 下面3种方式之一
              - …
            - `stamp` object — 仅当sub_type为stamp时有值，为印章识别结果
              - …
      - `raw_ocr` Ocrline[] — 全部文字识别结果，只包含文字结果。受URL参数page_details和raw_ocr影响，默认不返回
        - `text` string, required — 识别内容字符串
        - `score` number, float, required — 识别置信度（0 <= x <= 1）
        - `type` 'text' | 'formula', required — 文本类型，用于表示文字的形态。 当前版本下，文本类型包括： - text(文本) - formula(公式)
        - `position` integer[], required — 文本行的四个角点坐标，依次为左上，右上，右下，左下
        - `angle` integer, required — 图像（中文字）的角度（当输入为图像时，默认为0， 可选值0, 90, 180, 270)
        - `direction` -1 | 0 | 1 | 2, required — 文字阅读方向。 - -1: 其他 - 0: 单字 - 1: 横向 - 2: 纵向
        - `handwritten` -1 | 0 | 1, required — 文字是否手写所得。 - -1: 未知 - 0: 非手写文字, 一般为印刷文字 - 1: 文字手写, 一般具备明显的书写特征
        - `char_scores` number[] — 字符置信度，值域范围0-1。 设置char_details=1时输出。
        - `char_centers` array[] — 字符中心点。 设置character=1时输出。
          - integer[]
        - `char_positions` array[] — 字符四边形点坐标，以顺时针构成闭合区域。 设置char_details=1时输出。
          - integer[]
        - `char_candidates` array[] — 候选字数组，表示每一个字符的候选，与候选置信度配套使用。 设置char_details=1时输出。
          - string[]
        - `char_candidates_score` array[] — 候选字置信度数组，表示每一个候选字符的置信度，与候选字符配套使用。 设置char_details=1时输出。
          - number[]
      - `structured` union[] — 结构化数据, 为textblock, table, imageblock, footer, header中的一种
        - union
          - Textblock — 段落块
            - `type` string, required — 段落块类型， 固定为 textblock
            - `pos` integer[], required — 文本行四个角点
            - `origin_position` integer[] — 仅当打开切边时返回，表示该段落在原图中的坐标。格式同pos。
            - `content` integer[], required — 段落块内文本行id数据组
            - `sub_type` 'catalog' | 'text' | 'text_title' | 'image_title' | 'table_title' — 段落块字类型，包括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, required — 表格块类型, 固定为table
            - `sub_type` 'bordered' | 'borderless' — 表格子属性，取值为bordered(有线表)或borderless(无线表)，默认为bordered(即json中无该字段时，默认值为bordered)
            - `pos` integer[], required — 文本行四个角点坐标
            - `origin_position` integer[] — 仅当打开切边时返回，表示该表格在原图中的坐标。格式同pos。
            - `rows` integer, required — 表格行数
            - `cols` integer, required — 表格列数
            - `columns_width` integer[], required — 表格列宽度列表
            - `rows_height` integer[], required — 表格行高度列表
            - `text` string — 表格文本内容，以html或md格式展示
            - `continue` boolean — 当前表格与后一表格连续，用来判断一个表格是否被页面分割（如果 continue为true 且该表格位于本页结尾，该表格可与下一页开头表格组合为一个表格）
            - `caption_id` object — 表格的标题id
              - …
            - `cells` object[], required — 单元格数组
              - …
          - Imageblock — 图像块
            - `type` string, required — 图像块类型， 值为 image
            - `pos` integer[], required — 文本行四个角点坐标
            - `origin_position` integer[] — 仅当打开切边时返回，表示该子图在原图中的坐标。格式同pos。
            - `lines` integer[] — 图像包含的文本行id,
            - `content` integer[], required — 图像资源数据id数组
            - `caption_id` object — 图片的标题id
              - …
            - `text` string — 子图片识别得到的文本内容
          - Footer — 页脚
            - `type` string, required — 页脚块类型，固定为 footer
            - `pos` integer[], required — 文本行四个角点坐标
            - `blocks` union[], required — footer段落内容，为textblock, imageblock, table中其中的一种
              - …
          - Header — 页眉
            - `type` string, required — 页眉块类型，固定为 header
            - `pos` integer[], required — 文本行四个角点坐标
            - `blocks` union[], required — header段落内容，为textblock, imageblock, table中的其中一种
              - …
    - `catalog` object — 目录树结构。受参数catalog_details和apply_document_tree影响。
      - `toc` object[] — 返回的table of contents
        - `sub_type` string — 标题类型 text_title、 image_title、 table_title
        - `hierarchy` integer, required — 标题层级， 1 是 1级标题, 2 是 2级标题，依次类推
        - `title` string, required — 标题内容
        - `page_id` integer, required — 标题所在页码 （最小页码为 1)
        - `pos` integer[], required — 目录区域的四个角点坐标，依次为左上，右上，右下，左下
    - `total_page_number` integer — 输入PDF时， 返回文档的总页数
    - `valid_page_number` integer — 记录本次解析成功的总页数
    - `excel_base64` string — excel的base64结果，仅当get_excel=1时返回。
    - `success_count` integer — 解析成功页数。当parse_mode为lite时返回。
    - `elements` Element[] — 元素数组。当parse_mode为lite时返回此字段，替代原有的detail和pages结构。 如需将elements格式转换为统一的`detail`/`pages`格式，请参考[转换脚本](/xparse/parse-quickstart#elements格式转换脚本)。
      - `element_id` string, required — 唯一标识
      - `type` 'NarrativeText' | 'Title' | 'Table' | 'TableCaption' | 'Image' | 'FigureCaption' | 'Formula' | 'Header' | 'Footer' | 'CodeSnippet' | 'PageNumber' | 'UncategorizedText', required — 类型，具体见Element type类型说明
      - `text` string, required — 文本内容
      - `metadata` ElementMetadata, required — 元素元数据
        - `page_image_url` string, required — 页图url
        - `original_image_url` string — 原始页图url，仅当开启去水印或切边时返回
        - `angle` integer, required — 页面角度
        - `page_number` integer, required — 页码
        - `page_width` integer, required — 页宽
        - `page_height` integer, required — 页高
        - `coordinates` number[], required — element的归一化坐标（六位小数）
        - `is_continue` boolean, required — 是否和下一个element合并
        - `category_depth` integer, required — 目录层级，0表示一级标题，1表示2级标题，依次增加。-1表示正文段落
        - `parent_id` string, required — 父节点的element_id。表格和图片等父节点为对应的表格标题和图片标题。文本段落的父节点为对应的文本标题
        - `sub_type` string — 仅当type为Image时返回，包括stamp, card, qrcode_barcode, chart
        - `image_url` string — 仅当type为Image 且请求参数 image_output_type=default 时返回，值为子图的url
        - `image_base64` string — 仅当type为Image 且请求参数 image_output_type=base64str时返回，值为子图的base64字符串
  - `version` string, required — doc_restore 引擎版本号
  - `duration` integer, required — 引擎耗时 （毫秒）
  - `metrics` object[], required — 每一页的信息
    - `page_image_width` integer, required — 当前段落所在页的图片宽或者pdf转成的图片宽
    - `page_image_height` integer, required — 当前段落所在页的图片高或者pdf转成的图片高
    - `dpi` integer — 当前pdf页转成图片所用的dpi
    - `durations` number, float, required — 当前页总耗时
    - `status` string, required — 当前页状态
    - `page_id` number, required — 当前页码
    - `angle` 0 | 90 | 180 | 270, required — 图像角度， 定义0度为人类阅读文字的图像方向，称为正置图像， 本字段表示输入图像是正置图像进行顺时针若干角度的旋转所得。 - 0: ▲ - 90: ▶ - 180: ▼ - 270: ◀
    - `image_id` string — 当前页图片id （下载方式：https://api.textin.com/ocr_image/download?image_id=xxx, 需要在headers里添加appid和key, 有效期30天） \ 例如使用curl下载: \ curl 'https://api.textin.com/ocr_image/download?image_id=xxx' \ --header 'x-ti-app-id: c81f*************************e9ff' \ --header 'x-ti-secret-code: 5508***********************1c17'

---

[API](https://skmtc.dev/textin/apis/api.md) · [All operations](https://skmtc.dev/textin/apis/api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/textin/api/revisions/80992397e92f/schema)
