Render pixel-perfect invoice PDFs from HTML templates. Pay per page.
HTML2DocHub is the fastest way to generate invoice PDFs programmatically. Pass your HTML invoice template with dynamic data, get back a signed URL to a PDF. Supports async generation with webhook callbacks for bulk invoice runs.
const invoiceHtml = `<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; padding: 40px; }
.header { display: flex; justify-content: space-between; margin-bottom: 40px; }
.logo { color: #6366f1; font-size: 24px; font-weight: bold; }
table { width: 100%; border-collapse: collapse; }
th { background: #f8fafc; padding: 10px; text-align: left; border-bottom: 2px solid #e2e8f0;...`;
const response = await fetch("https://api.html2dochub.com/v1/render", {
method: "POST",
headers: {
"X-API-Key": "sk_live_YOUR_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
type: "pdf",
html: invoiceHtml,
options: {
format: "A4",
print_background: true,
margin_top: "1.5cm",
margin_bottom: "1.5cm",
},
tag: "invoice", // tag for filtering in dashboard
}),
});
const { download_url, final_cost } = await response.json();
// Send download_url to customer emailimport requests
INVOICE_TEMPLATE = open("invoice_template.html").read()
def generate_invoice(invoice_data: dict) -> str:
"""Render invoice PDF and return download URL."""
html = INVOICE_TEMPLATE.format(**invoice_data)
resp = requests.post(
"https://api.html2dochub.com/v1/render",
headers={"X-API-Key": "sk_live_YOUR_KEY"},
json={
"type": "pdf",
"mode": "async",
"html": html,
"options": {"format": "A4"},
"webhook_url": "https://yourapp.com/webhooks/invoice-ready",
"idempotency_key": f"invoice-{invoice_data['invoice_id']}",
"tag": "invoice",
},
)
data = resp.json()
return data["job_id"] # Poll or wait for webhookPay only for pages rendered. No subscriptions. No minimum monthly fee.
Free account. No credit card required. API ready in minutes.
Get your free API key