文档转换成 pdf
将文档格式转换成 pdf
请求说明
| 请求地址 | /v7/developer/weboffice/office/convert/to/pdf |
|---|---|
| 请求方法 | POST |
| 权限要求 | 查询和管理格式转换 kso.format_conversion.readwrite |
目前支持的文档类型
| 文档类型 | 扩展名 |
|---|---|
| 演示 | .pptx .ppt |
| WPS 文字 | .docx .doc |
| WPS 表格 | .xlsx .xls |
Header 参数
| 参数 | 必须 | 类型 | 说明 |
|---|---|---|---|
| Content-Type | 是 | string | 目前固定为: application/json |
| Authorization | 是 | string | 授权凭证,格式为:Bearer {access_token} |
Body 参数
| 参数 | 必须 | 类型 | 说明 |
|---|---|---|---|
| url | 是 | string | 文档下载地址 |
| filename | 是 | string | 文档名称,包含扩展名,例如:文字文稿.docx |
| password | 否 | string | 文档打开密码(如果文档有加密,该项则必填) |
| from_page | 否 | int | 转换起始页,从 1 开始计数(与 ranges互斥) |
| to_page | 否 | int | 转换结束页,需要大于 from_page, (与 ranges互斥) |
| show_comments | 否 | int | 是否显示批注。默认值为 false,不显示批注 |
返回参数
| 参数 | 必须 | 类型 | 说明 |
|---|---|---|---|
| code | 是 | integer | 错误码 |
| data | 是 | data {} | 响应数据 |
| > task_id | 是 | string | 转换任务 id |
示例
请求示例
httpsnippet
{"method":"POST","url":"https://openapi.wps.cn/v7/developer/weboffice/office/convert/to/pdf","headers":{"Content-Type":"application/json","Authorization":"Bearer ejxxx"},"data":{"url": "https://***.com/***","filename":"文字文稿.docx"}}
返回示例
json
{
"code": 0,
"data": {
"task_id": "open:zjsiwfuotpbqblrlfwtkfkioargjbla"
},
"result": "ok"
}
查询异步任务结果
携带 task_id查询结果
其中 result 对象说明
| 参数 | 必须 | 类型 | 说明 |
|---|---|---|---|
| pdfs | 否 | pdf[] | 转换后的 pdf 文档列表 |
| > url | 是 | string | 转换后的 pdf 文档下载地址(半小时有效) |
| > size | 是 | int | 转换后的 pdf 文档大小(以字节为单位) |
返回示例
json
{
"code": 0,
"data": {
"status": "success",
"progress": 100,
"result": {
"pdfs": [
{
"url": "https://***.com/***",
"size": 1063532
}
],
"task":{"elapsed":7892,"resource_size":1070216}
}
}
}
错误码
请参考错误码说明