Seamlessly convert PDFs and other documents to various formats like Word, Excel, images, and more with our powerful API.
The Conversion API enables developers to convert PDFs and other document formats to a wide range of output formats, including Word, Excel, PowerPoint, images, and text. It supports password-protected PDFs, OCR for text extraction, and customizable quality settings for image outputs.
POST https://mega-pdf.com/api/convert
Authenticate requests using an API key in the x-api-key
header or as a query parameter (api_key
).
// Header example
x-api-key: your-api-key
// Query parameter example
https://mega-pdf.com/api/convert?api_key=your-api-key
The API supports the following input and output formats:
The API accepts multipart/form-data
requests with the following parameters:
Parameter | Type | Description | Required |
---|---|---|---|
file | File | The input file to convert | Yes |
inputFormat | String | Input file format (optional if detectable from file extension) | No |
outputFormat | String | Desired output format | Yes |
ocr | Boolean | Enable OCR for text extraction (for PDF to TXT) | No |
quality | Number | Image quality (1-100) for image outputs | No (default: 90) |
password | String | Password for encrypted PDFs | No |
Convert a PDF to DOCX using cURL:
curl -X POST https://mega-pdf.com/api/convert \
-H "x-api-key: your-api-key" \
-F "file=@/path/to/document.pdf" \
-F "outputFormat=docx"
Successful responses include the converted file URL and metadata:
{
"success": true,
"message": "Conversion successful",
"fileUrl": "/api/file?folder=conversions&filename=uuid-output.docx",
"filename": "uuid-output.docx",
"originalName": "document.pdf",
"inputFormat": "pdf",
"outputFormat": "docx"
}
Error responses:
{
"success": false,
"error": "Invalid or unsupported output format"
}
Using the Conversion API with JavaScript (Node.js):
const formData = new FormData();
formData.append('file', fs.createReadStream('document.pdf'));
formData.append('outputFormat', 'docx');
fetch('https://mega-pdf.com/api/convert', {
method: 'POST',
headers: {
'x-api-key': 'your-api-key'
},
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
console.log('Conversion successful:', data.fileUrl);
} else {
console.error('Conversion failed:', data.error);
}
})
.catch(error => console.error('Error:', error));