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
Parameter
| 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). |
Contoh
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
Jika berjaya (200): bait mentah fail yang telah ditukar, dengan header Content-Type dan Content-Disposition ditetapkan untuknya. Jika gagal: badan JSON berbentuk {"error": {"code": "...", "message": "..."}} dengan kod status HTTP yang sepadan — lihat Ralat di bawah.
| Header | Value |
|---|---|
Content-Type | Jenis MIME sebenar fail yang telah ditukar (cth. image/png, application/pdf). |
Content-Disposition | attachment; filename="..." — cadangan nama fail, sama seperti muat turun fail lain. |
Content-Length | Saiz badan respons dalam bait. |
Setiap ralat mengikut bentuk JSON yang sama, contohnya apabila kuota melebihi had:
{
"error": {
"code": "quota_exceeded",
"message": "Monthly API allowance of 5000 conversion-minutes reached.",
"limit": 5000,
"used": 5000
}
}
Ralat
Setiap kegagalan memulangkan sampul ralat JSON dengan "code" yang boleh digunakan kod anda untuk bercabang, ditambah "message" yang boleh dibaca manusia. Sesetengah ralat menyertakan medan tambahan (quota_exceeded menyertakan "limit" dan "used", sebagai contoh).
| Status & code | When it happens |
|---|---|
401 missing_key | Tiada header Authorization dihantar. |
401 invalid_key | Kunci tersebut tidak wujud, atau telah dibatalkan. |
403 account_suspended | Akaun yang memiliki kunci ini telah digantung. |
403 plan_required | Akaun berada pada pelan Percuma — akses API memerlukan Basic, Lite, Pro, atau Team. |
400 invalid_category | "category" bukan "image" atau "document". |
400 missing_target | "target" kosong. |
400 no_file | Tiada fail dihantar, atau muat naik gagal — medan itu mesti dinamakan "file". |
413 file_too_large | Fail melebihi saiz muat naik maksimum pelan anda. |
429 quota_exceeded | Peruntukan minit penukaran bulanan pelan telah habis digunakan. Direset pada awal bulan kalendar berikutnya. |
429 concurrency_limit | Terlalu banyak penukaran sedang berjalan serentak untuk akaun ini (dikongsi dengan laman web) — tunggu sehingga salah satu selesai dan cuba lagi. |
422 conversion_failed | Fail itu sendiri tidak dapat ditukar — "message" menerangkan sebabnya. Kod status berbeza mengikut sebab: 400/415/422 bermaksud fail atau target tidak akan berfungsi tidak kira berapa kali anda cuba semula; 500/503 bermaksud masalah di pihak pelayan, dan 503 khususnya berbaloi untuk dicuba semula dengan singkat. |
Supported conversions
Diterima sebagai sumber:
PDF, DOCX, DOC, PPTX, PPT, XLSX, XLS, RTF, ODT, ODP, ODS, HTML
Tersedia sebagai sasaran:
PDF, DOCX, DOC, PPTX, PPT, XLSX, XLS, RTF, ODT, ODP, ODS