PDF Conversion API
Turn a PDF into an editable DOCX, XLSX, or PPTX, or go the other way — Word/Excel/PowerPoint to PDF — with one POST request.
curl -X POST \ .../api/v1/convert.php \ -H "Authorization: Bearer ..." \ -F "category=document" \ -F "target=DOCX" \ -F "file=@report.pdf" \ -o output.docx
https://transconvert.com/api/v1/convert.php
Parameters
| Field | Description |
|---|---|
Authorization | Required. "Bearer tc_live_...". |
category | Set to "document". |
target | Required. Output format code — "DOCX"/"XLSX"/"PPTX" when converting FROM a PDF, or "PDF" when converting a Word/Excel/PowerPoint file TO one. |
file | Required. The PDF (or the Word/Excel/PowerPoint file, when converting to PDF). |
Voorbeelden
curl -X POST \ https://transconvert.com/api/v1/convert.php \ -H "Authorization: Bearer tc_live_your_key_here" \ -F "category=document" \ -F "target=DOCX" \ -F "file=@report.pdf" \ -o output.docx
<?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' => 'DOCX', 'file' => new CURLFile('report.pdf'), ], ]); $response = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($status === 200) { file_put_contents('output.docx', $response); } else { $error = json_decode($response, true); echo $error['error']['message']; }
const form = new FormData(); form.append('category', 'document'); form.append('target', 'DOCX'); form.append('file', new Blob([fs.readFileSync('report.pdf')]), 'report.pdf'); 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.docx', Buffer.from(await res.arrayBuffer())); } else { const { error } = await res.json(); console.error(error.message); }
import requests with open('report.pdf', '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': 'DOCX'}, files={'file': f}, ) if response.status_code == 200: with open('output.docx', '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.pdf') do |file| req = Net::HTTP::Post::Multipart.new url, 'category' => 'document', 'target' => 'DOCX', 'file' => UploadIO.new(file, 'application/octet-stream', 'report.pdf') 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.docx', 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", "DOCX") .addFormDataPart("file", "report.pdf", RequestBody.create(new File("report.pdf"), 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.docx"), response.body().bytes()); } else { System.err.println(response.body().string()); } }
Respons
Bij succes (200): de ruwe bytes van het geconverteerde bestand, met bijbehorende Content-Type- en Content-Disposition-headers. Bij een fout: een JSON-body in de vorm {"error": {"code": "...", "message": "..."}} met een passende HTTP-statuscode — zie Fouten hieronder.
| Header | Value |
|---|---|
Content-Type | Het werkelijke MIME-type van het geconverteerde bestand (bijv. image/png, application/pdf). |
Content-Disposition | attachment; filename="..." — een voorgestelde bestandsnaam, net als bij elke bestandsdownload. |
Content-Length | Grootte van de response body in bytes. |
Elke fout volgt dezelfde JSON-structuur, bijvoorbeeld wanneer een quotum wordt overschreden:
{
"error": {
"code": "quota_exceeded",
"message": "Monthly API allowance of 5000 conversion-minutes reached.",
"limit": 5000,
"used": 5000
}
}
Fouten
Elke fout retourneert een JSON-foutobject met een "code" waarop je code kan vertakken, plus een leesbaar "message". Sommige fouten bevatten extra velden (quota_exceeded bevat bijvoorbeeld "limit" en "used").
| Status & code | When it happens |
|---|---|
401 missing_key | Er is geen Authorization-header meegestuurd. |
401 invalid_key | De sleutel bestaat niet, of is ingetrokken. |
403 account_suspended | Het account waartoe deze sleutel behoort, is geschorst. |
403 plan_required | Het account heeft het gratis abonnement — voor API-toegang is Basic, Lite, Pro of Team vereist. |
400 invalid_category | "category" was niet "image" of "document". |
400 missing_target | "target" was leeg. |
400 no_file | Er is geen bestand verzonden, of de upload is mislukt — het veld moet "file" heten. |
413 file_too_large | Het bestand overschrijdt de maximale uploadgrootte van je abonnement. |
429 quota_exceeded | De maandelijkse toewijzing conversieminuten van het abonnement is op. Wordt gereset aan het begin van de volgende kalendermaand. |
429 concurrency_limit | Er lopen al te veel conversies tegelijk voor dit account (gedeeld met de website) — wacht tot er één klaar is en probeer het opnieuw. |
422 conversion_failed | Het bestand zelf kon niet worden geconverteerd — "message" legt uit waarom. De statuscode varieert met de reden: 400/415/422 betekenen dat het bestand of target nooit zal werken, hoe vaak je het ook probeert; 500/503 duiden op een probleem aan de serverkant, en bij 503 is een korte nieuwe poging de moeite waard. |
Supported conversions
Geaccepteerd als bron:
PDF, DOCX, DOC, PPTX, PPT, XLSX, XLS, RTF, ODT, ODP, ODS, HTML
Beschikbaar als target:
PDF, DOCX, DOC, PPTX, PPT, XLSX, XLS, RTF, ODT, ODP, ODS