# 图片转为文档

将图片转换为文档格式，当前支持的图片格式：`png`、 `jpg`、 `jpeg`、 `bmp`、 `tif`、 `tiff`、 `gif`。



:::warning 注意
1. 测试应用单次最多可转换3张图片。
2. 单张图片支持的最大尺寸为50M。
:::

#### 目前支持转换为的文档类型：
| 文档类型 | 扩展名                                                                                                    |
| -------- | ------------------------------ |
| 文字     |`docx`|
| 表格     |`xlsx`|
| 演示     |`pptx`|
| JSON     |`json`|
| 表格提取     |`table`|

## 基本信息{#base}

请求路径：`POST /api/developer/v1/office/img/convert/to/:office_type`

## Header 参数{#header}

| 参数          | 必须 | 类型   | 说明                                                                                                |
| ------------- | ---- | ------ | --------------------------------------------------------------------------------------------------- |
| Date          | 是   | string | 使用 [RFC1123](https://datatracker.ietf.org/doc/html/rfc822#section-5) 时间格式的当前时间           |
| Content-Md5   | 是   | string | `HTTP Body` 中数据的 `MD5` 值十六进制表达方式, 必需小写, 如果是 `get` 请求一律使用 `URI` 计算 `MD5` |
| Content-Type  | 是   | string | 目前固定为: `application/json`                                                                      |
| Authorization | 是   | string | "WPS-2:" + `app_id` + ":" + sha1( `app_key` + `Content-Md5` + `Content-Type` + `DATE`)              |

## Path 参数{#path}

| 参数    | 必须 | 类型   | 说明            |
| ------- | ---- | ------ | --------------- |
| office_type | 是   | string | 转换为的文件类型：`docx`,`xlsx`,`pptx`,`json`,`table` |

## Body 参数{#body}

| 参数     | 必须 | 类型   | 说明                                     |
| -------- | ---- | ------ | ---------------------------------------- |
| img_urls      | 是   | array |图片url集合                           |
| text_unify | 否   | boolean | 统一段落字体字号，建议传true |
| sheet_option | 否   | integer | `转换为表格`时配置：sheet转换方式 0表示每页pdf(每页图片)一个sheet, 1表示所有页面（图片）转到一个sheet中， 默认为0 |
| export_type | 否   | string | `表格提取`时配置，输出类型：xlsx，html，默认为html |

## 返回参数{#return}
<!-- complex-table -->

| 参数 | 必须 | 类型 | 说明 |
| --- | --- | --- | --- |
| code | 是 | integer | 错误码 |
| data | 是 | data {} | 响应数据 |
| > task_id | 是 | string | 转换任务 id |

## 示例{#example}

#### 请求示例

:::httpsnippet `{"method":"POST","url":"https://solution.wps.cn/api/developer/v1/office/img/convert/to/docx","headers":{"Date":"Wed, 23 Jan 2013 06:43:08 GMT","Content-Md5":"d41d8cd98f00b204e9800998ecf8427e","Content-Type":"application/json","Authorization":"WPS-2:******:ac59dac1460772a04b3a97d7ef78409f28241e3a"},"data":{"img_urls": ["https://***.com/***"]}}`
:::

#### 返回示例

```json
{
    "code": 0,
    "data": {
        "task_id": "0f27ff302780428e9ddfd39189731891"
    }
}
```

## 查询异步任务结果

携带 task_id [查询结果](/app-integration-dev/docs-center/convert/api-docs/ocr/to-docs-status.html)

:::warning 提示
task_id 有效期1个小时。超过一个小时，将自动删除本次转换结果缓存，请及时保存相关转换结果及文件。
:::


## 错误码{#code}

请参考[错误码说明](./error.md)