Menu
Docs/PDF Generation

PDF Generation

Generate pixel-perfect PDFs from professional built-in templates or your own HTML. Use for invoices, certificates, reports, receipts, and business letters.

PDF generation is available on Starter plan and above.

Endpoints

POST/v1/pdf
GET/v1/pdf/templates

Generate a PDF

From a built-in template

{
  "template": "invoice",
  "data": {
    "company_name": "Acme Corp",
    "invoice_number": "INV-2024-001",
    "date": "January 15, 2024",
    "due_date": "February 15, 2024",
    "bill_to_name": "John Doe",
    "bill_to_address": "123 Main St, New York, NY 10001",
    "items": [
      { "description": "Web Design", "quantity": 10, "rate": 150 },
      { "description": "Hosting (1 year)", "quantity": 1, "rate": 120 }
    ],
    "subtotal": "1620.00",
    "total": "1620.00"
  }
}

From custom HTML

{
  "html": "<html><body><h1>My Document</h1><p>Content here.</p></body></html>",
  "format": "A4",
  "landscape": false
}
ParameterTypeDefaultDescription

Response

Binary PDF file with Content-Type: application/pdf and Content-Disposition: attachment.

Built-in templates

List all available templates:

curl https://api.snapsharp.dev/v1/pdf/templates
{
  "templates": [
    {
      "id": "invoice",
      "name": "Invoice",
      "variables": ["company_name", "invoice_number", "date", "due_date", "items", "subtotal", "total", "bill_to_name", "bill_to_address"]
    },
    {
      "id": "certificate",
      "name": "Certificate",
      "variables": ["recipient_name", "course_name", "date", "issuer_name", "certificate_id"]
    },
    {
      "id": "report",
      "name": "Report",
      "variables": ["title", "date", "author", "sections"]
    },
    {
      "id": "receipt",
      "name": "Receipt",
      "variables": ["store_name", "items", "total", "payment_method", "date"]
    },
    {
      "id": "letter",
      "name": "Business Letter",
      "variables": ["from_name", "from_address", "to_name", "to_address", "date", "subject", "body"]
    }
  ]
}

Template variables reference

invoice

VariableDescription
company_nameYour company name
company_logoURL to company logo image
invoice_numberInvoice identifier (e.g. INV-2024-001)
dateIssue date
due_datePayment due date
bill_to_nameClient name
bill_to_addressClient address (can include \n for newlines)
itemsArray of { description, quantity, rate }
subtotalSubtotal amount (string)
taxTax amount (optional)
totalTotal amount
payment_infoPayment instructions (optional)

certificate

VariableDescription
recipient_namePerson being certified
course_nameCourse or achievement name
dateIssue date
issuer_nameIssuing organization
issuer_logoURL to issuer logo (optional)
certificate_idUnique certificate ID (optional)

report

VariableDescription
titleReport title
dateReport date
authorAuthor name
sectionsArray of { title, content, image?, image_caption? }. content supports HTML.

receipt

VariableDescription
store_nameStore or business name
store_addressStore address (optional)
itemsArray of { name, quantity, price }
subtotalSubtotal (optional)
taxTax (optional)
totalTotal amount
payment_methode.g. "Credit Card", "Cash"
dateTransaction date

letter

VariableDescription
from_nameSender name
from_addressSender address
to_nameRecipient name
to_addressRecipient address
dateLetter date
subjectLetter subject
bodyLetter body (HTML supported)
salutationOpening greeting (optional, default: "Dear {to_name},")
closingClosing line (optional, default: "Sincerely,")
signature_titleTitle/position under name (optional)

Examples

cURL — Invoice PDF

curl -X POST https://api.snapsharp.dev/v1/pdf \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "template": "invoice",
    "data": {
      "company_name": "Acme Corp",
      "invoice_number": "INV-001",
      "date": "Jan 15, 2024",
      "due_date": "Feb 15, 2024",
      "bill_to_name": "Jane Smith",
      "bill_to_address": "456 Oak Ave, Chicago, IL",
      "items": [{"description": "Consulting", "quantity": 8, "rate": 200}],
      "subtotal": "1600.00",
      "total": "1600.00"
    }
  }' \
  -o invoice.pdf

Node.js

const fs = require('fs');

const response = await fetch('https://api.snapsharp.dev/v1/pdf', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk_live_...',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    template: 'certificate',
    data: {
      recipient_name: 'Alice Johnson',
      course_name: 'Advanced TypeScript',
      date: 'March 31, 2024',
      issuer_name: 'Tech Academy',
      certificate_id: 'CERT-2024-0042',
    },
  }),
});

const buffer = await response.arrayBuffer();
fs.writeFileSync('certificate.pdf', Buffer.from(buffer));

Python

import requests

response = requests.post(
    'https://api.snapsharp.dev/v1/pdf',
    headers={'Authorization': 'Bearer sk_live_...'},
    json={
        'template': 'receipt',
        'data': {
            'store_name': 'Coffee House',
            'items': [
                {'name': 'Latte', 'quantity': 2, 'price': 5.50},
                {'name': 'Croissant', 'quantity': 1, 'price': 3.00},
            ],
            'total': '14.00',
            'payment_method': 'Credit Card',
            'date': '2024-01-15 09:30',
        },
    },
)

with open('receipt.pdf', 'wb') as f:
    f.write(response.content)

Add page numbers and branding to every page using header_html and footer_html:

{
  "html": "<h1>Annual Report 2024</h1><p>Long content...</p>",
  "footer_html": "<div style='font-size:10px;text-align:center;width:100%;color:#999'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>"
}

The special classes pageNumber and totalPages are automatically populated by the browser.

Plan limits

PlanPDF GenerationTemplates
Free
Starter5 built-in
Growth5 built-in
BusinessAll + custom
EnterpriseAll + custom