Marketing Examples

Ready-to-use code examples for flyers, vouchers, event tickets, and labels

This page contains copy-paste examples for common marketing use cases: event tickets with QR codes, discount vouchers, and product labels. All examples use the Generate PDF endpoint.

Event ticket with QR code

Generate a simple ticket with a placeholder for a QR code image (you can generate the QR code image URL via your backend or a QR service and pass it in data.qrCodeUrl).

cURL

curl -X POST https://api.docreate.io/api/pdf/external \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<div class=\"ticket\"><h1>{{eventName}}</h1><p>{{date}} · {{venue}}</p><p class=\"code\">Ticket #{{ticketId}}</p><img src=\"{{qrCodeUrl}}\" alt=\"QR\" width=\"120\" height=\"120\" /></div>",
    "css": "body { font-family: Helvetica, sans-serif; padding: 24px; } .ticket { border: 2px dashed #333; padding: 24px; max-width: 400px; } .code { font-size: 12px; color: #666; } img { display: block; margin-top: 16px; }",
    "data": {
      "eventName": "Tech Conference 2026",
      "date": "March 15, 2026",
      "venue": "Convention Center",
      "ticketId": "TIX-8842",
      "qrCodeUrl": "https://api.qrserver.com/v1/create-qr-code/?size=120x120&data=TIX-8842"
    }
  }' \
  --output ticket.pdf

Node.js

const response = await fetch('https://api.docreate.io/api/pdf/external', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.DOCREATE_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    html: '<div class="ticket"><h1>{{eventName}}</h1><p>{{date}} · {{venue}}</p><p class="code">Ticket #{{ticketId}}</p><img src="{{qrCodeUrl}}" alt="QR" width="120" height="120" /></div>',
    css: 'body { font-family: Helvetica, sans-serif; padding: 24px; } .ticket { border: 2px dashed #333; padding: 24px; max-width: 400px; } .code { font-size: 12px; color: #666; } img { margin-top: 16px; }',
    data: {
      eventName: 'Tech Conference 2026',
      date: 'March 15, 2026',
      venue: 'Convention Center',
      ticketId: 'TIX-8842',
      qrCodeUrl: 'https://api.qrserver.com/v1/create-qr-code/?size=120x120&data=TIX-8842',
    },
  }),
});
const pdfBuffer = Buffer.from(await response.arrayBuffer());
await require('fs/promises').writeFile('ticket.pdf', pdfBuffer);

Discount voucher

A single voucher PDF with code and validity period. Use the same pattern in a loop to generate many vouchers with different codes.

cURL

curl -X POST https://api.docreate.io/api/pdf/external \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<div class=\"voucher\"><h2>20% Off</h2><p>Code: <strong>{{voucherCode}}</strong></p><p>Valid until {{validUntil}}</p><p class=\"small\">{{terms}}</p></div>",
    "css": "body { font-family: Helvetica, sans-serif; padding: 32px; } .voucher { text-align: center; border: 2px solid #1a1a2e; padding: 32px; max-width: 360px; } .small { font-size: 10px; color: #666; margin-top: 16px; }",
    "data": {
      "voucherCode": "SAVE20-XK9P",
      "validUntil": "2026-12-31",
      "terms": "One per customer. Not valid with other offers."
    }
  }' \
  --output voucher.pdf

Python

import requests
import os

resp = requests.post(
    'https://api.docreate.io/api/pdf/external',
    headers={
        'Authorization': f'Bearer {os.environ["DOCREATE_API_KEY"]}',
        'Content-Type': 'application/json',
    },
    json={
        'html': '<div class="voucher"><h2>20% Off</h2><p>Code: <strong>{{voucherCode}}</strong></p><p>Valid until {{validUntil}}</p><p class="small">{{terms}}</p></div>',
        'css': 'body { font-family: Helvetica, sans-serif; padding: 32px; } .voucher { text-align: center; border: 2px solid #1a1a2e; padding: 32px; max-width: 360px; } .small { font-size: 10px; color: #666; margin-top: 16px; }',
        'data': {
            'voucherCode': 'SAVE20-XK9P',
            'validUntil': '2026-12-31',
            'terms': 'One per customer. Not valid with other offers.',
        },
    },
)
if resp.status_code == 200:
    with open('voucher.pdf', 'wb') as f:
        f.write(resp.content)

Product label with barcode

Example with a barcode image URL (replace with your barcode generator or image URL).

Node.js

const response = await fetch('https://api.docreate.io/api/pdf/external', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.DOCREATE_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    html: '<div class="label"><h3>{{productName}}</h3><p>SKU: {{sku}}</p><img src="{{barcodeUrl}}" alt="Barcode" height="48" /><p class="price">{{price}}</p></div>',
    css: 'body { font-family: Helvetica, sans-serif; padding: 16px; } .label { border: 1px solid #eee; padding: 16px; width: 240px; } .price { font-weight: bold; font-size: 18px; }',
    data: {
      productName: 'Widget Pro',
      sku: 'WIDGET-001',
      barcodeUrl: 'https://barcode.tec-it.com/barcode.ashx?data=WIDGET-001&code=Code128',
      price: '€29.99',
    },
  }),
});
const pdfBuffer = Buffer.from(await response.arrayBuffer());
await require('fs/promises').writeFile('label.pdf', pdfBuffer);

Next steps