Word document conversion

Word to PDF
API Documentation

Convert Microsoft Word (.docx) documents into print-ready PDF files with layout and formatting preserved โ€” synchronously or through async jobs โ€” over a simple REST API. Built for developers.

Try it now Back to API Hub

Overview

The Word to PDF API converts Microsoft Word (.docx) documents into PDF files while preserving fonts, tables, images, and page layout. Synchronous conversion is ideal for small documents; the async endpoints are designed for larger files or batch workflows. Every conversion job is tracked in the server database for status polling and secure downloads.

Base URL & Authentication

Base URL

Base URL

https://api.chemhub.com/api/v1

Authentication

Include your API credentials in every request header.

Headers

X-API-Key: your_api_key
X-API-Secret: your_secret
Content-Type: application/json

Get API Keys

Follow these steps to obtain your API credentials:

1

Log In to Your Account

Existing Users: Go to /login to access your dashboard

New Users: Visit /register to create your free account first

2

Access Your Profile

Once you log in, click on your profile picture in the top-right corner, then click on "Your profile" from the dropdown menu.

3

Create API Key

From your profile page, proceed to the "API Keys" section and create a key by filling in a name you prefer.

Example name

"Word converter bot" or "My Document Pipeline"

4

Save Your Credentials

Click on "Create API Key" to generate your credentials, then immediately copy and save both the API Key and Secret.

Critical Warning

Your secret key will only be displayed once! Copy it immediately and store it securely. You won't be able to see it again.

Security Notice

Never share your API keys publicly or commit them to version control. Treat them like passwords โ€” regenerate immediately if compromised.

Rate Limits

15 requests per minute per API key. Check your dashboard for current usage and limits.

Endpoints

๐Ÿ’š Health CheckGET /word2pdf/health
๐Ÿ”„ Convert Word to PDFPOST /word2pdf/convert
โณ Convert (Async)POST /word2pdf/convert/async
๐Ÿ“‹ Job StatusGET /word2pdf/jobs/{job_id}
โฌ‡๏ธ Download ResultGET /word2pdf/jobs/{job_id}/download

Health Check

GET/word2pdf/health

Health check endpoint to verify the Word to PDF service status, available backends, and supported formats.

Response

Success Response

{
  "success": true,
  "status": "healthy",
  "w2p_backends": {
    "docx_reportlab": true
  },
  "supported_formats": [".docx"],
  "max_file_size_mb": 10,
  "database_available": true,
  "timestamp": "2026-08-07T12:00:00"
}

Code Examples

Python

import requests

url = "https://api.chemhub.com/api/v1/word2pdf/health"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret"
}

res = requests.get(url, headers=headers)
print(res.json())

cURL

curl -X GET https://api.chemhub.com/api/v1/word2pdf/health \
-H "X-API-Key: your_api_key" \
-H "X-API-Secret: your_secret"

JavaScript

fetch('https://api.chemhub.com/api/v1/word2pdf/health', {
  method: 'GET',
  headers: {
    'X-API-Key': 'your_api_key',
    'X-API-Secret': 'your_secret'
  }
})
.then(res => res.json())
.then(console.log);

Convert Word to PDF

POST/word2pdf/convert

Convert a Word document to a PDF synchronously. Upload the file as multipart/form-data.

Form Parameters

FieldTypeDefaultDescription
fileFileโ€”DOCX file (required) โ€” up to 10MB
backendstringdocx_reportlabConversion backend (only docx_reportlab is available)
Response

On success the endpoint returns the converted PDF bytes directly with Content-Type: application/pdf.

cURL Example

cURL

curl -X POST "https://api.chemhub.com/api/v1/word2pdf/convert" \
  -H "X-API-Key: your_api_key" \
  -H "X-API-Secret: your_secret" \
  -F "file=@document.docx" \
  -F "backend=docx_reportlab" \
  --output document.pdf

Code Examples

Python

import requests

url = "https://api.chemhub.com/api/v1/word2pdf/convert"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret"
}

with open("document.docx", "rb") as f:
    files = {"file": f}
    data = {"backend": "docx_reportlab"}
    response = requests.post(url, headers=headers, files=files, data=data)

if response.status_code == 200:
    with open("document.pdf", "wb") as out:
        out.write(response.content)
    print("Conversion successful!")
else:
    print(response.json())

JavaScript

const form = new FormData();
form.append('file', fileInput.files[0]);
form.append('backend', 'docx_reportlab');

fetch('https://api.chemhub.com/api/v1/word2pdf/convert', {
  method: 'POST',
  headers: {
    'X-API-Key': 'your_api_key',
    'X-API-Secret': 'your_secret'
  },
  body: form
})
.then(async res => {
  if (res.ok) {
    const blob = await res.blob();
    const url = URL.createObjectURL(blob);
    console.log('PDF URL:', url);
  } else {
    console.log(await res.json());
  }
});

Convert Word to PDF (Async)

POST/word2pdf/convert/async

Submit a conversion job and receive a job_id immediately. Use the job endpoints to poll for progress and download the result. Ideal for large files or batch workflows.

Form Parameters

Same parameters as the synchronous endpoint.

FieldTypeDefaultDescription
fileFileโ€”DOCX file (required) โ€” up to 10MB
backendstringdocx_reportlabConversion backend (only docx_reportlab is available)

Response

Success Response

{
  "success": true,
  "job_id": "b21e6d9f0a3c4e2b",
  "status": "queued",
  "message": "Document conversion started. Use the job ID to check status."
}

Code Examples

Python

import requests

url = "https://api.chemhub.com/api/v1/word2pdf/convert/async"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret"
}

with open("document.docx", "rb") as f:
    response = requests.post(url, headers=headers, files={"file": f}, data={"backend": "docx_reportlab"})

result = response.json()
job_id = result.get("job_id")
print("Job ID:", job_id)

cURL

curl -X POST "https://api.chemhub.com/api/v1/word2pdf/convert/async" \
  -H "X-API-Key: your_api_key" \
  -H "X-API-Secret: your_secret" \
  -F "file=@document.docx" \
  -F "backend=docx_reportlab"

Get Job Status

GET/word2pdf/jobs/{job_id}

Poll the status of an asynchronous conversion job. Job statuses are queued, processing, done, and failed.

Path Parameters

FieldTypeDescription
job_idstringJob ID returned by the async submit endpoint (required)

Response

Success Response

{
  "success": true,
  "job_id": "b21e6d9f0a3c4e2b",
  "status": "done",
  "filename": "document.docx",
  "created_at": "2026-08-07 12:00:01",
  "updated_at": "2026-08-07 12:00:05",
  "result_url": "/api/v1/word2pdf/jobs/b21e6d9f0a3c4e2b/download"
}
Ownership

Jobs are bound to the API key that created them. Accessing another key's job returns 403 Access denied.

Code Examples

Python

import requests

job_id = "b21e6d9f0a3c4e2b"
url = f"https://api.chemhub.com/api/v1/word2pdf/jobs/{job_id}"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret"
}

res = requests.get(url, headers=headers)
print(res.json())

cURL

curl -X GET "https://api.chemhub.com/api/v1/word2pdf/jobs/b21e6d9f0a3c4e2b" \
  -H "X-API-Key: your_api_key" \
  -H "X-API-Secret: your_secret"

Download Conversion Result

GET/word2pdf/jobs/{job_id}/download

Download the PDF produced by a completed async job.

Path Parameters

FieldTypeDescription
job_idstringJob ID of a completed (done) job (required)
Response

On success the endpoint returns the converted PDF as an attachment. If the job has not finished, it returns 400 Job not completed.

cURL Example

cURL

curl -X GET "https://api.chemhub.com/api/v1/word2pdf/jobs/b21e6d9f0a3c4e2b/download" \
  -H "X-API-Key: your_api_key" \
  -H "X-API-Secret: your_secret" \
  --output converted.pdf

Python SDK

Complete Python SDK covering health check, synchronous conversion, async job submission, polling, and download.

Complete SDK Class

import requests

BASE_URL = "https://api.chemhub.com/api/v1"
API_KEY = "YOUR_API_KEY"
API_SECRET = "YOUR_API_SECRET"

headers = {
    "X-API-Key": API_KEY,
    "X-API-Secret": API_SECRET
}

# --- Health Check ---
def check_health():
    return requests.get(f"{BASE_URL}/word2pdf/health", headers=headers).json()

# --- Synchronous conversion ---
def convert_sync(docx_path):
    with open(docx_path, "rb") as f:
        files = {"file": f}
        data = {"backend": "docx_reportlab"}
        response = requests.post(
            f"{BASE_URL}/word2pdf/convert",
            headers=headers,
            files=files,
            data=data
        )
    if response.status_code == 200:
        output_path = docx_path.rsplit(".", 1)[0] + ".pdf"
        with open(output_path, "wb") as out:
            out.write(response.content)
        print(f"Saved: {output_path}")
        return output_path
    print(f"Error: {response.status_code} - {response.text}")
    return None

# --- Async conversion ---
def convert_async(docx_path):
    with open(docx_path, "rb") as f:
        files = {"file": f}
        data = {"backend": "docx_reportlab"}
        response = requests.post(
            f"{BASE_URL}/word2pdf/convert/async",
            headers=headers,
            files=files,
            data=data
        )
    return response.json()

# --- Poll job status ---
def get_job_status(job_id):
    return requests.get(
        f"{BASE_URL}/word2pdf/jobs/{job_id}",
        headers=headers
    ).json()

# --- Download completed job ---
def download_job(job_id, output_path="converted.pdf"):
    response = requests.get(
        f"{BASE_URL}/word2pdf/jobs/{job_id}/download",
        headers=headers
    )
    if response.status_code == 200:
        with open(output_path, "wb") as out:
            out.write(response.content)
        print(f"Downloaded: {output_path}")
    else:
        print(f"Error: {response.status_code} - {response.text}")

# --- Test all endpoints ---
if __name__ == "__main__":
    print("=== WORD TO PDF API TEST ===")
    health = check_health()
    print(f"Health: {health.get('status', 'unknown')}")

    job = convert_async("document.docx")
    print(f"Submitted job: {job.get('job_id')}")
    print("Poll and download with get_job_status() / download_job().")

Errors & Status Codes

Error Response Format

Error Response

{
  "success": false,
  "error": "Invalid file",
  "message": "File too large. Max size is 10MB"
}

Status Codes

CodeMeaning
200Success
400Bad request / invalid parameters / unsupported file format
401Invalid or missing API key/secret
403Access denied (job belongs to another API key)
404Job not found or result unavailable
429Rate limit exceeded
500Internal server error / conversion failed

Limitations

Maximum file size: 10MB
Supported formats: DOCX (.docx) only
Rate limit: 15 requests per minute
Backends: docx_reportlab
Output: PDF with preserved layout and formatting