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/pdfGET
/v1/pdf/templatesGenerate 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
}| Parameter | Type | Default | Description |
|---|
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
| Variable | Description |
|---|---|
company_name | Your company name |
company_logo | URL to company logo image |
invoice_number | Invoice identifier (e.g. INV-2024-001) |
date | Issue date |
due_date | Payment due date |
bill_to_name | Client name |
bill_to_address | Client address (can include \n for newlines) |
items | Array of { description, quantity, rate } |
subtotal | Subtotal amount (string) |
tax | Tax amount (optional) |
total | Total amount |
payment_info | Payment instructions (optional) |
certificate
| Variable | Description |
|---|---|
recipient_name | Person being certified |
course_name | Course or achievement name |
date | Issue date |
issuer_name | Issuing organization |
issuer_logo | URL to issuer logo (optional) |
certificate_id | Unique certificate ID (optional) |
report
| Variable | Description |
|---|---|
title | Report title |
date | Report date |
author | Author name |
sections | Array of { title, content, image?, image_caption? }. content supports HTML. |
receipt
| Variable | Description |
|---|---|
store_name | Store or business name |
store_address | Store address (optional) |
items | Array of { name, quantity, price } |
subtotal | Subtotal (optional) |
tax | Tax (optional) |
total | Total amount |
payment_method | e.g. "Credit Card", "Cash" |
date | Transaction date |
letter
| Variable | Description |
|---|---|
from_name | Sender name |
from_address | Sender address |
to_name | Recipient name |
to_address | Recipient address |
date | Letter date |
subject | Letter subject |
body | Letter body (HTML supported) |
salutation | Opening greeting (optional, default: "Dear {to_name},") |
closing | Closing line (optional, default: "Sincerely,") |
signature_title | Title/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.pdfNode.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)Custom header and footer
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
| Plan | PDF Generation | Templates |
|---|---|---|
| Free | ❌ | — |
| Starter | ✅ | 5 built-in |
| Growth | ✅ | 5 built-in |
| Business | ✅ | All + custom |
| Enterprise | ✅ | All + custom |