A newer version of the Gradio SDK is available:
6.5.1
Enhanced DOCX to PDF Converter API Documentation
Overview
This is a professional FastAPI-based service for converting DOCX files to PDF with perfect formatting preservation, especially optimized for Arabic RTL text.
Base URL
http://localhost:8000
Endpoints
1. Health Check
GET /health
Check if the service is running.
Response:
{
"status": "healthy",
"version": "2.0.0"
}
2. Convert DOCX to PDF
POST /convert
Convert a single DOCX file to PDF. Supports two input methods:
Method 1: Multipart File Upload
Form Parameters:
file(required): The DOCX file to convert
Method 2: Base64 Encoded Content
Form Parameters:
file_content(required): Base64 encoded DOCX file contentfilename(required): Original filename with .docx extension
Response:
{
"success": true,
"pdf_url": "/download/abc123/document.pdf",
"message": "Conversion successful"
}
Error Response:
{
"success": false,
"error": "Error description"
}
3. Batch Convert DOCX to PDF
POST /convert/batch
Convert multiple DOCX files to PDF in a single request.
Request Body:
{
"files": [
{
"file_content": "base64_encoded_content_1",
"filename": "document1.docx"
},
{
"file_content": "base64_encoded_content_2",
"filename": "document2.docx"
}
]
}
Response:
[
{
"success": true,
"pdf_url": "/download/abc123/document1.pdf",
"message": "Conversion successful"
},
{
"success": false,
"error": "Error description"
}
]
4. Download PDF
GET /download/{temp_id}/{filename}
Download a converted PDF file.
Path Parameters:
temp_id: Temporary directory ID from conversion responsefilename: PDF filename from conversion response
Error Handling
The API uses standard HTTP status codes:
200- Success400- Bad Request (invalid input)404- Not Found (file not found)413- Payload Too Large (file too big)500- Internal Server Error (conversion failed)
File Size Limits
- Maximum file size: 50MB
- Supported file type: DOCX only
CORS Support
The API includes full CORS support for direct browser integration.
Example Usage
Using cURL (File Upload)
curl -X POST "http://localhost:8000/convert" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "file=@document.docx"
Using cURL (Base64)
curl -X POST "http://localhost:8000/convert" \
-H "accept: application/json" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "file_content=$(base64 document.docx)" \
-d "filename=document.docx"
Using JavaScript (Fetch API)
const formData = new FormData();
formData.append('file', fileInput.files[0]);
fetch('http://localhost:8000/convert', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.open('http://localhost:8000' + data.pdf_url, '_blank');
}
});