fmard/pdf-api
0
PDF Generator API
Convert HTML to PDF using headless Chromium. Supports raw HTML, Jinja2 templates, and custom page options.
API Endpoints
POST /api/generate — Generate PDF from HTML
Request body (JSON):
{
"html": "<html><body><h1>Hello World</h1></body></html>",
"options": {
"format": "A4",
"landscape": false,
"margin": { "top": "20mm", "right": "20mm", "bottom": "20mm", "left": "20mm" },
"scale": 1.0,
"printBackground": true
}
}Using a built-in template:
{
"template": "invoice",
"data": {
"company_name": "Acme Inc.",
"client_name": "John Doe",
"invoice_number": "INV-001",
"date": "2024-01-15",
"due_date": "2024-02-15",
"items": [
{ "description": "Web Development", "quantity": 1, "price": 5000 }
],
"tax_rate": 10
}
}Response: PDF binary file (Content-Type: application/pdf)
GET /api/health — Health check
Returns: {"status": "healthy", "service": "pdf-generator-api"}
GET /api/templates — List built-in templates
Returns: {"templates": ["invoice", "receipt", "report", "resume"]}
Built-in Templates
PDF Options
Rate Limits
- 100 requests per hour per IP
- Maximum HTML size: 5MB
- Generation timeout: 30 seconds
Deployment
This project is configured for deployment on HuggingFace Spaces using Docker. Simply push to your HF Space repository and it will build and deploy automatically.
Local Development
pip install -r requirements.txt
playwright install chromium
uvicorn main:app --reload --port 7860