跳转到主要内容
TransConvert

Document Conversion API

Convert PDF, Word, PowerPoint, Excel, and OpenDocument files with one POST request — including turning a PDF back into an editable DOCX or XLSX.

POST https://transconvert.com/api/v1/convert.php

参数

Field Description
AuthorizationRequired. "Bearer tc_live_...".
categorySet to "document".
targetRequired. Output format code, e.g. "PDF", "DOCX", "XLSX".
fileRequired. The document to convert.

示例

TransConvert
curl -X POST \
  https://transconvert.com/api/v1/convert.php \
  -H "Authorization: Bearer tc_live_your_key_here" \
  -F "category=document" \
  -F "target=PDF" \
  -F "file=@report.docx" \
  -o output.pdf

响应

成功时(200):返回转换后文件的原始字节,并设置相应的 Content-Type 和 Content-Disposition 响应头。失败时:返回如 {"error": {"code": "...", "message": "..."}} 结构的 JSON,并附带相应的 HTTP 状态码——请参见下方的错误说明。

Header Value
Content-Type转换后文件的实际 MIME 类型(例如 image/png、application/pdf)。
Content-Dispositionattachment; filename="..."——建议的文件名,与普通文件下载相同。
Content-Length响应体的大小(字节)。

所有错误都遵循相同的 JSON 结构,例如超出额度时:

429 Too Many Requests
{
  "error": {
    "code": "quota_exceeded",
    "message": "Monthly API allowance of 5000 conversion-minutes reached.",
    "limit": 5000,
    "used": 5000
  }
}

错误

每个失败请求都会返回一个 JSON 错误信息,其中包含可供代码判断分支的 "code",以及便于阅读的 "message"。部分错误还包含额外字段(例如 quota_exceeded 会包含 "limit" 和 "used")。

Status & code When it happens
401 missing_key未发送 Authorization 请求头。
401 invalid_key密钥不存在,或已被撤销。
403 account_suspended拥有此密钥的账户已被暂停。
403 plan_required该账户为 Free 套餐——API 访问权限需要 Basic、Lite、Pro 或 Team 套餐。
400 invalid_category"category" 既不是 "image" 也不是 "document"。
400 missing_target"target" 为空。
400 no_file未发送文件,或上传失败——字段名必须为 "file"。
413 file_too_large文件大小超出您所在套餐的最大上传限制。
429 quota_exceeded该套餐每月的转换分钟数已用完,将于下个自然月初重置。
429 concurrency_limit此账户同时运行的转换任务过多(与网站共用限额)——请等待其中一个完成后重试。
422 conversion_failed文件本身无法转换——"message" 中会说明原因。状态码会因原因而异:400/415/422 表示无论重试多少次,该文件或目标格式都无法成功;500/503 表示服务器端出现问题,其中 503 值得进行一次短暂重试。

Supported formats

可作为源格式:

PDF, DOCX, DOC, PPTX, PPT, XLSX, XLS, RTF, ODT, ODP, ODS, HTML

可作为目标格式:

PDF, DOCX, DOC, PPTX, PPT, XLSX, XLS, RTF, ODT, ODP, ODS

相关内容