html4pdf

Document Templates

Generate professional documents without writing HTML. Just provide your data.

Available Templates

  • Invoice - Professional invoices with itemized billing
  • Receipt - Clean receipts for transactions
  • Contract - Formal agreements with signatures

Invoice Template

const response = await fetch('https://api.html4pdf.com/generate-pdf', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    template: {
      type: "invoice",
      data: {
        company: {
          name: "ACME Corporation",
          address: "123 Business St, SF, CA 94102",
          email: "[email protected]",
          phone: "+1 (555) 123-4567"
        },
        client: {
          name: "Client Company Inc",
          address: "456 Client Ave, NY, NY 10001"
        },
        invoice: {
          number: "INV-2024-001",
          date: "January 15, 2024",
          dueDate: "February 15, 2024"
        },
        items: [
          {
            description: "Web Development Services",
            quantity: 40,
            rate: 150.00,
            amount: 6000.00
          },
          {
            description: "UI/UX Design",
            quantity: 20,
            rate: 120.00,
            amount: 2400.00
          }
        ],
        subtotal: 8400.00,
        tax: 840.00,
        total: 9240.00,
        notes: "Payment due within 30 days"
      },
      theme: {
        primaryColor: "#2563eb"
      }
    }
  })
});

const { pdf } = await response.json();
import requests

response = requests.post(
    'https://api.html4pdf.com/generate-pdf',
    headers={'Authorization': 'Bearer YOUR_API_KEY'},
    json={
        'template': {
            'type': 'invoice',
            'data': {
                'company': {
                    'name': 'ACME Corporation',
                    'address': '123 Business St, SF, CA 94102',
                    'email': '[email protected]',
                    'phone': '+1 (555) 123-4567'
                },
                'client': {
                    'name': 'Client Company Inc',
                    'address': '456 Client Ave, NY, NY 10001'
                },
                'invoice': {
                    'number': 'INV-2024-001',
                    'date': 'January 15, 2024',
                    'dueDate': 'February 15, 2024'
                },
                'items': [
                    {
                        'description': 'Web Development',
                        'quantity': 40,
                        'rate': 150.00,
                        'amount': 6000.00
                    }
                ],
                'subtotal': 6000.00,
                'tax': 600.00,
                'total': 6600.00
            },
            'theme': {'primaryColor': '#2563eb'}
        }
    }
)

pdf = response.json()['pdf']
curl -X POST https://api.html4pdf.com/generate-pdf \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": {
      "type": "invoice",
      "data": {
        "company": {
          "name": "ACME Corporation",
          "email": "[email protected]"
        },
        "client": {
          "name": "Client Company Inc"
        },
        "invoice": {
          "number": "INV-001",
          "date": "January 15, 2024"
        },
        "items": [{
          "description": "Services",
          "quantity": 1,
          "rate": 1000,
          "amount": 1000
        }],
        "subtotal": 1000,
        "total": 1000
      }
    }
  }'

Required Fields

FieldDescription
company.nameYour company name
client.nameClient name
invoice.numberInvoice number
invoice.dateInvoice date
itemsArray of line items
subtotalSubtotal amount
totalTotal amount

Optional Fields

  • logo - URL to company logo
  • company.address, company.email, company.phone
  • client.address, client.email
  • invoice.dueDate
  • tax, discount
  • notes - Additional notes
  • theme.primaryColor - Brand color (hex)

Receipt Template

const response = await fetch('https://api.html4pdf.com/generate-pdf', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    template: {
      type: "receipt",
      data: {
        business: {
          name: "Coffee Shop",
          address: "789 Main St, Austin, TX",
          phone: "+1 (555) 987-6543"
        },
        receipt: {
          number: "RCP-12345",
          date: "January 15, 2024, 10:30 AM",
          paymentMethod: "Credit Card ****1234"
        },
        items: [
          {
            name: "Cappuccino (Large)",
            quantity: 2,
            price: 4.50,
            total: 9.00
          },
          {
            name: "Blueberry Muffin",
            quantity: 1,
            price: 3.50,
            total: 3.50
          }
        ],
        subtotal: 12.50,
        tax: 1.25,
        total: 13.75,
        footer: "Thank you for your visit!"
      },
      theme: {
        primaryColor: "#10b981"
      }
    }
  })
});
response = requests.post(
    'https://api.html4pdf.com/generate-pdf',
    headers={'Authorization': 'Bearer YOUR_API_KEY'},
    json={
        'template': {
            'type': 'receipt',
            'data': {
                'business': {
                    'name': 'Coffee Shop',
                    'address': '789 Main St',
                    'phone': '+1 (555) 987-6543'
                },
                'receipt': {
                    'number': 'RCP-12345',
                    'date': 'January 15, 2024',
                    'paymentMethod': 'Credit Card'
                },
                'items': [
                    {
                        'name': 'Cappuccino',
                        'quantity': 2,
                        'price': 4.50,
                        'total': 9.00
                    }
                ],
                'subtotal': 9.00,
                'tax': 0.90,
                'total': 9.90
            }
        }
    }
)

Required Fields

FieldDescription
business.nameBusiness name
receipt.numberReceipt number
receipt.dateTransaction date/time
itemsPurchased items
subtotalSubtotal
totalTotal paid

Contract Template

const response = await fetch('https://api.html4pdf.com/generate-pdf', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    template: {
      type: "contract",
      data: {
        title: "Service Agreement",
        date: "January 15, 2024",
        parties: [
          {
            name: "Service Provider LLC",
            role: "Provider",
            address: "123 Business St, SF, CA"
          },
          {
            name: "Client Company Inc",
            role: "Client",
            address: "456 Client Ave, NY, NY"
          }
        ],
        terms: [
          {
            title: "1. Scope of Work",
            content: "Provider agrees to deliver services..."
          },
          {
            title: "2. Payment Terms",
            content: "Client agrees to pay $50,000..."
          }
        ],
        signatures: [
          {
            name: "John Smith",
            title: "CEO, Service Provider LLC",
            date: "January 15, 2024"
          },
          {
            name: "Jane Doe",
            title: "CTO, Client Company Inc",
            date: "January 15, 2024"
          }
        ]
      },
      theme: {
        primaryColor: "#1f2937"
      }
    }
  })
});
response = requests.post(
    'https://api.html4pdf.com/generate-pdf',
    headers={'Authorization': 'Bearer YOUR_API_KEY'},
    json={
        'template': {
            'type': 'contract',
            'data': {
                'title': 'Service Agreement',
                'date': 'January 15, 2024',
                'parties': [
                    {
                        'name': 'Service Provider LLC',
                        'role': 'Provider'
                    },
                    {
                        'name': 'Client Company Inc',
                        'role': 'Client'
                    }
                ],
                'terms': [
                    {
                        'title': '1. Scope',
                        'content': 'Provider agrees...'
                    }
                ],
                'signatures': [
                    {
                        'name': 'John Smith',
                        'title': 'CEO',
                        'date': 'Jan 15, 2024'
                    }
                ]
            }
        }
    }
)

Required Fields

FieldDescription
titleContract title
dateContract date
partiesArray of parties
termsArray of terms

Theme Colors

Customize the brand color for any template:

theme: {
  primaryColor: "#2563eb"  // Your brand color
}

Suggested colors:

  • Blue: #2563eb (professional)
  • Green: #10b981 (finance)
  • Gray: #1f2937 (legal)
  • Slate: #0f172a (corporate)

Next Steps