Convert DOCX to PDF from your code
Learn how to integrate the HelloDocxToPdf API into your application.
Quick Start
Convert a DOCX file to PDF with a single API call. Include your API key in the Authorization header.
curl -X POST https://www.hellodocxtopdf.com/api/convert \
-H "Authorization: Bearer hpdf_your_api_key" \
-F "file=@document.docx" \
-o output.pdfAuthentication
All API requests require authentication using an API key. Include your key in the Authorization header:
Authorization: Bearer hpdf_your_api_keyTip: You can create and manage your API keys in the Credentials section.
Convert Endpoint
/api/convertConvert a DOCX file to PDF format.
Request
Send a multipart/form-data request with the file:
| Parameter | Type | Description |
|---|---|---|
file | File | The DOCX file to convert (required) |
Response
Returns the converted PDF file as binary data with the following headers:
| Header | Description |
|---|---|
Content-Type | application/pdf |
X-Credits-Used | Number of credits consumed |
X-Credits-Remaining | Remaining credits for the month |
X-Credits-Limit | Total monthly credit limit |
Code Examples
JavaScript / TypeScript
const formData = new FormData();
formData.append('file', docxFile);
const response = await fetch('https://www.hellodocxtopdf.com/api/convert', {
method: 'POST',
headers: {
'Authorization': 'Bearer hpdf_your_api_key'
},
body: formData
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.message);
}
const pdfBlob = await response.blob();
const pdfUrl = URL.createObjectURL(pdfBlob);
// Download the PDF
const link = document.createElement('a');
link.href = pdfUrl;
link.download = 'document.pdf';
link.click();Python
import requests
url = "https://www.hellodocxtopdf.com/api/convert"
headers = {"Authorization": "Bearer hpdf_your_api_key"}
with open("document.docx", "rb") as f:
files = {"file": ("document.docx", f, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")}
response = requests.post(url, headers=headers, files=files)
if response.status_code == 200:
with open("output.pdf", "wb") as pdf:
pdf.write(response.content)
print("PDF saved successfully!")
else:
print(f"Error: {response.json()}")Node.js
const fs = require('fs');
const FormData = require('form-data');
const form = new FormData();
form.append('file', fs.createReadStream('document.docx'));
const response = await fetch('https://www.hellodocxtopdf.com/api/convert', {
method: 'POST',
headers: {
'Authorization': 'Bearer hpdf_your_api_key',
...form.getHeaders()
},
body: form
});
const buffer = await response.arrayBuffer();
fs.writeFileSync('output.pdf', Buffer.from(buffer));
console.log('PDF saved successfully!');Error Handling
The API returns standard HTTP status codes. Errors include a JSON body with details:
| Status | Description |
|---|---|
200 | Success - PDF returned |
400 | Bad request - Invalid file or missing parameters |
401 | Unauthorized - Invalid or missing API key |
429 | Rate limited - Not enough credits |
500 | Server error - Conversion failed |
Error Response Example
{
"error": "Not enough credits",
"creditsNeeded": 3,
"creditsRemaining": 1,
"creditsLimit": 100,
"resetAt": "2025-02-01T00:00:00.000Z"
}Credit System
Credits are calculated based on file size:
1 credit = 5MB of file size (rounded up)
| File Size | Credits Used |
|---|---|
| 0 - 5 MB | 1 credit |
| 5 - 10 MB | 2 credits |
| 10 - 15 MB | 3 credits |
| And so on... | ceil(size / 5MB) |
Need Help?
If you have any questions or run into issues, contact us at support@hellodocxtopdf.com