Spaces:
Sleeping
Sleeping
File size: 5,423 Bytes
8e7152e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | ---
title: Document Conversion API
emoji: π
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
license: apache-2.0
app_port: 7860
---
# π Document Conversion API - Word to PDF
Free, self-hosted document conversion service using LibreOffice. Deploy on Hugging Face Spaces for unlimited FREE usage!
## β¨ Features
- **100% FREE** - No API keys, no limits, no credit card
- **High Quality** - Uses LibreOffice for professional PDF conversion
- **Fast** - Converts documents in seconds
- **Self-Hosted** - Complete control and privacy
- **Multiple Formats** - Supports DOCX, DOC, ODT, RTF, TXT β PDF
## π Quick Deploy to Hugging Face Spaces
### Step 1: Create a New Space
1. Go to [Hugging Face Spaces](https://huggingface.co/spaces)
2. Click **"Create new Space"**
3. Fill in:
- **Space name**: `nextools-doc-converter` (or your choice)
- **License**: Apache 2.0
- **Select the SDK**: **Docker**
- **Space hardware**: CPU basic (FREE)
- **Visibility**: Public
### Step 2: Upload Files
Upload these 3 files to your Space:
1. `Dockerfile`
2. `app.py`
3. `requirements.txt`
### Step 3: Wait for Build
- Hugging Face will automatically build your Docker container
- Takes about 5-10 minutes (first time only)
- Watch the logs for "Application startup complete"
### Step 4: Get Your API URL
Your API will be available at:
```
https://YOUR-USERNAME-nextools-doc-converter.hf.space
```
### Step 5: Add to Your Vercel .env.local
```bash
# Document Conversion API
DOC_CONVERSION_API_URL=https://YOUR-USERNAME-nextools-doc-converter.hf.space
```
## π‘ API Usage
### Convert Document to PDF
**Endpoint:** `POST /convert`
**cURL Example:**
```bash
curl -X POST \
https://YOUR-USERNAME-nextools-doc-converter.hf.space/convert \
-F "file=@document.docx" \
--output converted.pdf
```
**JavaScript Example:**
```javascript
const formData = new FormData();
formData.append('file', file);
const response = await fetch('https://YOUR-API-URL/convert', {
method: 'POST',
body: formData
});
const pdfBlob = await response.blob();
```
### Health Check
**Endpoint:** `GET /health`
```bash
curl https://YOUR-API-URL/health
```
**Response:**
```json
{
"status": "healthy",
"libreoffice": true,
"message": "Service is running"
}
```
## π§ Test Locally (Optional)
### Using Docker:
```bash
# Build
docker build -t doc-converter .
# Run
docker run -p 7860:7860 doc-converter
# Test
curl -X POST http://localhost:7860/convert \
-F "file=@test.docx" \
--output converted.pdf
```
### Using Python (requires LibreOffice installed):
```bash
# Install LibreOffice first:
# Ubuntu/Debian: sudo apt install libreoffice
# Mac: brew install libreoffice
# Windows: Download from libreoffice.org
# Install dependencies
pip install -r requirements.txt
# Run
python app.py
# Test
curl -X POST http://localhost:7860/convert \
-F "file=@test.docx" \
--output converted.pdf
```
## π Supported Formats
### Input Formats:
- `.docx` - Microsoft Word (2007+)
- `.doc` - Microsoft Word (97-2003)
- `.odt` - OpenDocument Text
- `.rtf` - Rich Text Format
- `.txt` - Plain Text
### Output Format:
- `.pdf` - PDF (Portable Document Format)
## π― Why Hugging Face Spaces?
1. **FREE Forever** - No billing, no credit card
2. **No Rate Limits** - Unlimited conversions
3. **Always Online** - 99.9% uptime
4. **Fast** - Global CDN delivery
5. **Easy Deploy** - Just upload files
6. **Auto-Scaling** - Handles traffic spikes
## π Security & Privacy
- Files are processed in memory
- Automatic cleanup after conversion
- No data is stored or logged
- CORS enabled for your domains
- SSL/HTTPS encryption
## π Troubleshooting
### Build Failed?
- Check Dockerfile syntax
- Ensure all files are uploaded
- Wait for LibreOffice installation to complete
### Conversion Failed?
- Check file format is supported
- Verify file is not corrupted
- Check logs in Hugging Face dashboard
### Timeout?
- Large files (>10MB) may take longer
- Consider increasing timeout in Dockerfile
- Split large documents
## π Notes
- **First conversion** may take 5-10 seconds (LibreOffice startup)
- **Subsequent conversions** are much faster (~1-2 seconds)
- **Maximum file size**: 50MB (configurable)
- **Concurrent requests**: Supported with workers
## π Integration with NexTools
Update your `app/api/pdf-convert/route.ts`:
```typescript
// Use Hugging Face API for Word to PDF
async function wordToPdf(fileBuffer: Buffer) {
const apiUrl = process.env.DOC_CONVERSION_API_URL;
if (!apiUrl) {
throw new Error('DOC_CONVERSION_API_URL not configured');
}
const formData = new FormData();
formData.append('file', new Blob([fileBuffer]), 'document.docx');
const response = await fetch(`${apiUrl}/convert`, {
method: 'POST',
body: formData,
});
if (!response.ok) {
throw new Error('Conversion failed');
}
const pdfBuffer = Buffer.from(await response.arrayBuffer());
return {
content: pdfBuffer.toString('base64'),
mimeType: 'application/pdf',
fileName: 'converted.pdf',
fileType: 'PDF',
pages: 1, // Calculate if needed
};
}
```
## π Support
- **Issues**: Report on GitHub
- **Questions**: Ask in Hugging Face discussions
- **Updates**: Watch this repository
## π License
Apache 2.0 License - Free for commercial and personal use
---
Made with β€οΈ for NexTools - Your All-in-One SaaS Platform
|