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.
curl -X POST \ .../api/v1/convert.php \ -H "Authorization: Bearer ..." \ -F "category=document" \ -F "target=PDF" \ -F "file=@report.docx" \ -o output.pdf
https://transconvert.com/api/v1/convert.php
Parámetros
| Field | Description |
|---|---|
Authorization | Required. "Bearer tc_live_...". |
category | Set to "document". |
target | Required. Output format code, e.g. "PDF", "DOCX", "XLSX". |
file | Required. The document to convert. |
Ejemplos
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
<?php $ch = curl_init('https://transconvert.com/api/v1/convert.php'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Authorization: Bearer tc_live_your_key_here'], CURLOPT_POSTFIELDS => [ 'category' => 'document', 'target' => 'PDF', 'file' => new CURLFile('report.docx'), ], ]); $response = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($status === 200) { file_put_contents('output.pdf', $response); } else { $error = json_decode($response, true); echo $error['error']['message']; }
const form = new FormData(); form.append('category', 'document'); form.append('target', 'PDF'); form.append('file', new Blob([fs.readFileSync('report.docx')]), 'report.docx'); const res = await fetch('https://transconvert.com/api/v1/convert.php', { method: 'POST', headers: { Authorization: 'Bearer tc_live_your_key_here' }, body: form, }); if (res.ok) { fs.writeFileSync('output.pdf', Buffer.from(await res.arrayBuffer())); } else { const { error } = await res.json(); console.error(error.message); }
import requests with open('report.docx', 'rb') as f: response = requests.post( 'https://transconvert.com/api/v1/convert.php', headers={'Authorization': 'Bearer tc_live_your_key_here'}, data={'category': 'document', 'target': 'PDF'}, files={'file': f}, ) if response.status_code == 200: with open('output.pdf', 'wb') as out: out.write(response.content) else: print(response.json()['error']['message'])
# gem install multipart-post require 'net/http' require 'net/http/post/multipart' url = URI('https://transconvert.com/api/v1/convert.php') File.open('report.docx') do |file| req = Net::HTTP::Post::Multipart.new url, 'category' => 'document', 'target' => 'PDF', 'file' => UploadIO.new(file, 'application/octet-stream', 'report.docx') req['Authorization'] = 'Bearer tc_live_your_key_here' res = Net::HTTP.start(url.host, url.port, use_ssl: true) do |http| http.request(req) end if res.code == '200' File.write('output.pdf', res.body) else puts JSON.parse(res.body)['error']['message'] end end
// Gradle: implementation("com.squareup.okhttp3:okhttp:4.+") OkHttpClient client = new OkHttpClient(); RequestBody body = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart("category", "document") .addFormDataPart("target", "PDF") .addFormDataPart("file", "report.docx", RequestBody.create(new File("report.docx"), MediaType.parse("application/octet-stream"))) .build(); Request request = new Request.Builder() .url("https://transconvert.com/api/v1/convert.php") .header("Authorization", "Bearer tc_live_your_key_here") .post(body) .build(); try (Response response = client.newCall(request).execute()) { if (response.isSuccessful()) { Files.write(Paths.get("output.pdf"), response.body().bytes()); } else { System.err.println(response.body().string()); } }
Respuesta
En caso de éxito (200): los bytes en bruto del archivo convertido, con las cabeceras Content-Type y Content-Disposition configuradas para él. En caso de error: un cuerpo JSON con la forma {"error": {"code": "...", "message": "..."}} y un código de estado HTTP correspondiente; consulta Errores más abajo.
| Header | Value |
|---|---|
Content-Type | El tipo MIME real del archivo convertido (p. ej. image/png, application/pdf). |
Content-Disposition | attachment; filename="..." — un nombre de archivo sugerido, igual que en cualquier descarga. |
Content-Length | Tamaño del cuerpo de la respuesta en bytes. |
Todos los errores siguen la misma estructura JSON; por ejemplo, al superar una cuota:
{
"error": {
"code": "quota_exceeded",
"message": "Monthly API allowance of 5000 conversion-minutes reached.",
"limit": 5000,
"used": 5000
}
}
Errores
Cada error devuelve un JSON con un "code" sobre el que tu código puede ramificarse, además de un "message" legible por humanos. Algunos errores incluyen campos adicionales (quota_exceeded incluye, por ejemplo, "limit" y "used").
| Status & code | When it happens |
|---|---|
401 missing_key | No se envió ninguna cabecera Authorization. |
401 invalid_key | La clave no existe, o ha sido revocada. |
403 account_suspended | La cuenta propietaria de esta clave está suspendida. |
403 plan_required | La cuenta está en el plan Free: el acceso a la API requiere Basic, Lite, Pro o Team. |
400 invalid_category | "category" no era "image" ni "document". |
400 missing_target | "target" estaba vacío. |
400 no_file | No se envió ningún archivo, o la subida falló; el campo debe llamarse "file". |
413 file_too_large | El archivo supera el tamaño máximo de subida permitido por tu plan. |
429 quota_exceeded | Se agotó la asignación mensual de minutos de conversión del plan. Se restablece al inicio del siguiente mes natural. |
429 concurrency_limit | Ya hay demasiadas conversiones en curso a la vez para esta cuenta (se comparte con el sitio web); espera a que termine una y vuelve a intentarlo. |
422 conversion_failed | El propio archivo no se pudo convertir; "message" explica el motivo. El código de estado varía según la causa: 400/415/422 significan que el archivo o el destino no funcionarán por más intentos que hagas; 500/503 indican un problema del lado del servidor, y en concreto 503 merece un breve reintento. |
Supported formats
Aceptados como origen:
PDF, DOCX, DOC, PPTX, PPT, XLSX, XLS, RTF, ODT, ODP, ODS, HTML
Disponibles como destino:
PDF, DOCX, DOC, PPTX, PPT, XLSX, XLS, RTF, ODT, ODP, ODS