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
พารามิเตอร์
| 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). |
ตัวอย่าง
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()); } }
การตอบกลับ
สำเร็จ (200): ไบต์ดิบของไฟล์ที่แปลงแล้ว พร้อมส่วนหัว Content-Type และ Content-Disposition ที่ตั้งค่าให้ ล้มเหลว: เนื้อหา JSON รูปแบบ {"error": {"code": "...", "message": "..."}} พร้อมรหัสสถานะ HTTP ที่ตรงกัน — ดู Errors ด้านล่าง
| Header | Value |
|---|---|
Content-Type | ประเภท MIME จริงของไฟล์ที่แปลงแล้ว (เช่น image/png, application/pdf) |
Content-Disposition | attachment; filename="..." — ชื่อไฟล์ที่แนะนำ เหมือนกับการดาวน์โหลดไฟล์ทั่วไป |
Content-Length | ขนาดเนื้อหาการตอบกลับเป็นไบต์ |
ข้อผิดพลาดทุกแบบมีโครงสร้าง JSON เดียวกัน ตัวอย่างเช่นเมื่อเกินโควตา:
{
"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 หมายความว่าไฟล์หรือ target นี้จะไม่สำเร็จไม่ว่าจะลองกี่ครั้งก็ตาม; 500/503 หมายถึงปัญหาฝั่งเซิร์ฟเวอร์ และ 503 โดยเฉพาะคุ้มค่าที่จะลองใหม่อีกครั้งในเวลาสั้นๆ |
Supported conversions
รองรับเป็นต้นทาง:
PDF, DOCX, DOC, PPTX, PPT, XLSX, XLS, RTF, ODT, ODP, ODS, HTML
ใช้เป็นปลายทางได้:
PDF, DOCX, DOC, PPTX, PPT, XLSX, XLS, RTF, ODT, ODP, ODS