curl https://api.dynamicdocumentapi.com/v1/pdf/from-template \
-H "Authorization: Bearer $DYNAMIC_DOCUMENT_API_KEY" \
-H "Idempotency-Key: pi_3Qk8sLd92" \
-H "Content-Type: application/json" \
-d '{
"template_id": "tpl_receipt_thermal",
"data": {
"receipt_no": "R-2026-18422",
"paid_at": "2026-09-25T10:14:02Z",
"method": "Visa •••• 4242",
"locale": "en-US",
"currency": "USD",
"items": [
{ "name": "Flat white", "qty": 2, "total": 7.80 },
{ "name": "Croissant", "qty": 1, "total": 3.68 }
],
"subtotal": 11.48, "tax": 1.42, "total": 12.90,
"reprint_url": "https://shop.example.com/r/R-2026-18422"
},
"pdf": {
"paper": { "width": "80mm" },
"single_page": true,
"margin": { "top": "4mm", "right": "3mm", "bottom": "4mm", "left": "3mm" },
"timezone": "America/New_York"
},
"delivery": "binary"
}' \
--output receipt.pdf
// Node.js 18+: called from your payment webhook handler
export async function receiptFor(payment) {
const res = await fetch("https://api.dynamicdocumentapi.com/v1/pdf/from-template", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.DYNAMIC_DOCUMENT_API_KEY}`,
"Idempotency-Key": payment.id, // providers retry webhooks
"Content-Type": "application/json",
},
body: JSON.stringify({
template_id: "tpl_receipt",
data: {
receipt_no: payment.receiptNo,
paid_at: payment.paidAt,
method: `${payment.brand} •••• ${payment.last4}`,
currency: payment.currency,
items: payment.items,
total: payment.total,
},
pdf: { paper: { format: "A4" } },
delivery: "binary", // bytes for the email attachment
}),
});
if (!res.ok) throw new Error(await res.text());
return Buffer.from(await res.arrayBuffer());
}
import os
import requests
def receipt_pdf(payment: dict, thermal: bool = False) -> bytes:
"""Called from the payment webhook. Returns PDF bytes."""
paper = {"width": "80mm"} if thermal else {"format": "A4"}
res = requests.post(
"https://api.dynamicdocumentapi.com/v1/pdf/from-template",
headers={
"Authorization": f"Bearer {os.environ['DYNAMIC_DOCUMENT_API_KEY']}",
"Idempotency-Key": payment["id"],
},
json={
"template_id": "tpl_receipt",
"data": payment,
"pdf": {"paper": paper, "single_page": thermal},
"delivery": "binary",
},
timeout=30,
)
res.raise_for_status()
return res.content
<?php
function receiptPdf(array $payment): string
{
$ch = curl_init('https://api.dynamicdocumentapi.com/v1/pdf/from-template');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('DYNAMIC_DOCUMENT_API_KEY'),
'Idempotency-Key: ' . $payment['id'],
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'template_id' => 'tpl_receipt',
'data' => $payment,
'pdf' => [
'paper' => ['width' => '58mm'], // narrow roll printer
'single_page' => true,
],
'delivery' => 'binary',
]),
]);
return curl_exec($ch); // PDF bytes
}