Word转PDF在线转换工具

简单、高效、安全的文档格式转换服务

API文档

API概述

我们提供RESTful API接口,让您可以轻松地将Word文档转换为PDF格式,集成到您的应用程序中。

1. 转换接口

POST/api/convert

请求说明

该接口用于上传Word文档并转换为PDF格式。

请求参数

  • file: 要转换的Word文档文件,支持.docx、.doc和.rtf格式

请求示例

import requests

files = {'file': open('example.docx', 'rb')}
response = requests.post('http://your-server/api/convert', files=files)

if response.status_code == 200:
    data = response.json()
    download_url = data['data']['download_url']
    print(f"转换成功,下载地址: {download_url}")
else:
    print(f"转换失败: {response.json()['message']}")

成功响应

{"status": "success",
 "data": {
   "original_filename": "example.docx",
   "download_url": "/download/xxx.pdf",
   "convert_time": 0.56,
   "timestamp": "2023-01-01 12:00:00"
 }}

失败响应

{"status": "error",
 "message": "转换失败: 具体错误信息"}

2. 下载接口

GET/download/{filename}

请求说明

该接口用于下载转换后的PDF文件。

URL参数

  • filename: 从转换接口返回的下载文件名

响应说明

成功请求将直接返回PDF文件的二进制数据,浏览器会触发文件下载。

如果文件不存在,将返回404错误,并包含错误信息。

3. 健康检查接口

GET/health

请求说明

该接口用于检查服务是否正常运行。

响应示例

{"status": "healthy"}

4. 统计信息接口

GET/stats

请求说明

该接口用于获取当前系统的转换统计信息。

响应示例

{"upload_files": 1234,
 "output_files": 1200,
 "upload_size_mb": 45.67,
 "output_size_mb": 34.56}

API使用注意事项

  • 文件转换后将在服务器上保留24小时,之后会被自动清理
  • 为了确保服务的稳定性,我们对API的调用频率进行了限制
  • 对于较大的文件,转换时间可能会较长,请设置合理的超时时间
  • 如需更多定制化的服务,请联系我们