templates

كيفية انشاء قالب PDF Boarding Pass

Create travel-ready boarding passes with scannable identifiers and strict space constraints. This tutorial shows a full template workflow you can ship today: preview the target output, copy the Typst template, pass dynamic data via API, and productionize with repeatable request payloads.

Updated 2026-02-19

1. What you'll build

You will build a Boarding Pass PDF template that accepts dynamic data and renders consistently across environments.

The final document includes branded header content, structured rows, and predictable totals suitable for programmatic generation.

2. The Typst template code (copyable)

#set page(paper: "a4", margin: 12pt)
#set text(font: "Inter", size: 10pt)

#let payload = sys.inputs

#grid(
  columns: (2fr, 1fr),
  gutter: 12pt,
  [#text(size: 18pt, weight: "bold")[Boarding Pass]],
  [#align(right)[#text(weight: "semibold")[#payload.document_id]]],
)

#v(8pt)
#line(length: 100%)
#v(8pt)

#for (label, value) in (
  ("Customer", payload.customer),
  ("Date", payload.date),
  ("Reference", payload.reference),
) {
  #grid(columns: (1fr, 2fr), [#text(fill: rgb("#666"))[#label]], [#value])
}

#v(10pt)
#table(
  columns: (2fr, auto, auto),
  inset: 6pt,
  stroke: rgb("#ddd"),
  [*Item*], [*Qty*], [*Amount*],
  ..payload.items.map(item => (
    item.name,
    str(item.qty),
    "$" + str(item.amount),
  )).flatten(),
)

#align(right)[#text(weight: "bold")[Total: $ #payload.total]]

3. Passing dynamic data via API

{
  "document_id": "DOC-1001",
  "customer": "Acme Fulfillment",
  "date": "2026-02-19",
  "reference": "REF-9920",
  "items": [
    { "name": "Widget A", "qty": 2, "amount": 49.99 },
    { "name": "Widget B", "qty": 1, "amount": 19.99 }
  ],
  "total": 119.97
}

4. Full API request example (curl)

curl -X POST "$DOCUFORGE_API_URL/v1/render" \
  -H "X-API-Key: $DOCUFORGE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "tpl_boarding_pass",
    "data": {
      "document_id": "DOC-1001",
      "customer": "Acme Fulfillment",
      "date": "2026-02-19",
      "reference": "REF-9920",
      "items": [
        { "name": "Widget A", "qty": 2, "amount": 49.99 },
        { "name": "Widget B", "qty": 1, "amount": 19.99 }
      ],
      "total": 119.97
    }
  }' \
  --output boarding-pass.pdf

4. Full API request example (JavaScript)

const response = await fetch(`${process.env.DOCUFORGE_API_URL}/v1/render`, {
  method: "POST",
  headers: {
    "X-API-Key": process.env.DOCUFORGE_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    template_id: "tpl_boarding_pass",
    data: payload,
  }),
});

const pdf = await response.arrayBuffer();

4. Full API request example (Python)

import requests

resp = requests.post(
    f"{API_URL}/v1/render",
    headers={"X-API-Key": API_KEY, "Content-Type": "application/json"},
    json={
        "template_id": "tpl_boarding_pass",
        "data": payload,
    },
    timeout=30,
)

with open("output.pdf", "wb") as f:
    f.write(resp.content)

5. Customization tips (logo, barcode, layout)

  • Keep document width and spacing constants in one place to avoid drift.
  • Prefer deterministic barcode input values generated by your backend.
  • Store brand colors and typography in template variables for easy theme updates.
  • Use reusable snippets for repeated footers, legal text, and totals.

6. جرب مباشرة

الاسئلة الشائعة

Can I reuse this boarding pass template across multiple customers?

Yes. Keep customer-specific values in the data payload and keep the layout logic in the template.

Which endpoint should I use in production?

Use POST /v1/render with an API key for production traffic, and POST /v1/render/preview for draft iteration.

محتوى مرتبط

Generate this with DocuForge in seconds

Use the same template in preview and production routes with a stable request payload.