A Node.js service for converting DOCX files to PDF using LibreOffice. Designed to run on Render, Fly.io, or any Node.js hosting platform and handle both synchronous and asynchronous document conversion.
- ✅ DOCX to PDF conversion using LibreOffice headless mode
- ✅ Asynchronous processing (non-blocking)
- ✅ Webhook callbacks for completion notifications
- ✅ Error handling and logging
- ✅ Health check endpoint
- ✅ Docker support
- Node.js 18+
- LibreOffice installed
- Render account (or any Node.js hosting)
- Clone the repository
- Install dependencies:
npm install
- Install LibreOffice:
# Ubuntu/Debian sudo apt-get update && sudo apt-get install -y libreoffice # macOS brew install libreoffice # Windows # Download from https://www.libreoffice.org/download/
- Run the service:
npm start
docker build -t render-pdf-service .
docker run -p 10000:10000 render-pdf-servicePORT- Server port (default: 10000)RENDER_WEBHOOK_SECRET- Secret for webhook verification (optional but recommended)NODE_ENV- Environment (development/production)
Convert a DOCX file to PDF.
Request:
{
"docxUrl": "https://example.com/document.docx",
"orderId": "ORD123456",
"callbackUrl": "https://your-app.vercel.app/api/webhooks/render"
}Response:
{
"success": true,
"jobId": "job_ORD123456_1234567890",
"message": "Conversion job started"
}The service will:
- Download the DOCX file from
docxUrl - Convert it to PDF using LibreOffice
- Send the PDF (base64 encoded) to
callbackUrlvia webhook
Convert a DOCX file to PDF synchronously (returns immediately with PDF).
Request:
{
"docxUrl": "https://example.com/document.docx"
}Response:
{
"success": true,
"pdfBuffer": "base64_encoded_pdf_content",
"size": 123456
}Health check endpoint.
Response:
{
"status": "ok",
"service": "word-pdf-service",
"timestamp": "2024-01-01T00:00:00.000Z"
}Check conversion status (placeholder - use webhook for completion).
When conversion completes, the service sends a POST request to callbackUrl:
Success:
{
"orderId": "ORD123456",
"jobId": "job_ORD123456_1234567890",
"pdfBuffer": "base64_encoded_pdf_content",
"status": "completed"
}Failure:
{
"orderId": "ORD123456",
"jobId": "job_ORD123456_1234567890",
"status": "failed",
"error": "Error message"
}- Install Fly CLI:
curl -L https://fly.io/install.sh | sh - Login:
fly auth login - Deploy:
fly deploy - The service will be available at
https://your-app-name.fly.dev
- Create a new Web Service on Render
- Connect your Git repository
- Render will automatically detect the Dockerfile
- Set environment variables:
RENDER_WEBHOOK_SECRET(optional)PORT(default: 10000)
- Deploy!
- Create a new Web Service on Render
- Connect your Git repository
- Set build command:
apt-get update && apt-get install -y libreoffice && npm install
- Set start command:
node server.js
- Set environment variables
- Deploy!
libreoffice --versionlibreoffice --headless --convert-to pdf --outdir ./output ./test.docxcurl -X POST http://localhost:10000/api/convert \
-H "Content-Type: application/json" \
-d '{
"docxUrl": "https://example.com/test.docx",
"orderId": "test123",
"callbackUrl": "https://your-app.vercel.app/api/webhooks/render"
}'- Ensure LibreOffice is installed in the Docker image
- Check PATH:
which libreoffice - Use full path:
/usr/bin/libreoffice
- Check Render logs for detailed error messages
- Verify DOCX file is accessible from Render
- Ensure sufficient disk space in temp directory
- Verify
callbackUrlis correct and accessible - Check
RENDER_WEBHOOK_SECRETmatches - Review Render logs for webhook errors
- First conversion may be slower (LibreOffice startup)
- Typical conversion: 5-30 seconds depending on document size
- Memory usage: ~200-500MB per conversion
- Always use HTTPS for webhook URLs
- Set
RENDER_WEBHOOK_SECRETfor webhook verification - Validate input URLs (ensure they're from trusted sources)
- Consider rate limiting for production
MIT