Live
Free tier included
Convert HTML to PDF via API
Transform HTML & CSS into professionally styled PDF documents. Custom page sizes, orientation, headers, footers — perfect for invoices, reports, and certificates.
A4 / Letter / A3
Headers & Footers
CSS Styling
No API Key
Interactive Playground
Try it Free
Write HTML, choose your settings, and generate a PDF instantly.
Try Free
Result
Write HTML and click Generate PDF
API Documentation
Convert any HTML/CSS content into a professionally styled PDF document. Supports custom page sizes, orientation, margins, headers, and footers.
Endpoint
POST
https://www.mahmoudalhabash.com/api/v1/html-to-pdf
Send an HTML string and configuration. The API renders the HTML into a PDF and returns a base64-encoded document you can download or embed.
Request Parameters
Response Fields
status "success" or "error"filename Generated filename with .pdf extensionpages Number of pages in the PDFsize_bytes File size in bytessize_human Human-readable file size (e.g. "24.5 KB")took_ms Processing time in millisecondspdf Base64-encoded data URI — use in download links or embedCode Examples
cURL
curl -X POST https://www.mahmoudalhabash.com/api/v1/html-to-pdf \
-H "Content-Type: application/json" \
-d '{
"html": "<h1>Invoice #001</h1><p>Total: $99</p>",
"format": "A4",
"orientation": "portrait",
"filename": "invoice-001"
}'
Response 200JSON
{
"status": "success",
"filename": "invoice-001.pdf",
"format": "A4",
"orientation": "portrait",
"pages": 1,
"size_bytes": 24567,
"size_human": "24 KB",
"took_ms": 890,
"pdf": "data:application/pdf;base64,JVBERi0x..."
}
JavaScript (fetch)
const res = await fetch('https://www.mahmoudalhabash.com/api/v1/html-to-pdf', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
html: document.getElementById('invoice').innerHTML,
format: 'A4',
filename: 'invoice'
})
});
const { pdf, filename } = await res.json();
// Trigger download
const a = document.createElement('a');
a.href = pdf;
a.download = filename;
a.click();
Python (requests)
import requests, base64
resp = requests.post(
'https://www.mahmoudalhabash.com/api/v1/html-to-pdf',
json={
'html': '<h1>Report</h1><p>Generated PDF</p>',
'format': 'A4',
'filename': 'report'
}
)
data = resp.json()
pdf_b64 = data['pdf'].split(',')[1]
with open(data['filename'], 'wb') as f:
f.write(base64.b64decode(pdf_b64))
print(f"Saved {data['filename']} ({data['size_human']})")
Error Codes
422 Validation failed — HTML is required (max 500KB)
429 Rate limit exceeded
500 PDF rendering failed — invalid HTML or internal error
Rate Limits
Unlimited — Free during beta
No API key required. HTML is rendered server-side using DomPDF. External images via URL are supported. JavaScript is not executed.