lightweight-pdfv0.3.0

← All examples

Template and data with the CLI

No Rust code: lwpdf render examples/invoice-template.json --data examples/invoice-data.json resolves the {{placeholders}} and the $each row repetition against the data file.

Template and data with the CLI

examples/invoice-template.json
// examples/invoice-template.json
{
  "schema_version": 1,
  "document": {
    "page_format": "A4",
    "margin": { "top": 40.0, "right": 40.0, "bottom": 40.0, "left": 40.0 },
    "metadata": { "title": "{{invoice.number}}" },
    "children": [
      {
        "type": "text",
        "content": "Rechnung {{invoice.number}}",
        "style": { "size": 22.0, "font": "sans-bold" }
      },
      {
        "type": "text",
        "content": "{{customer.name}}"
      },
      {
        "type": "table",
        "columns": [
          { "width": { "flex": 1.0 } },
          { "width": { "fixed": 80.0 }, "align": "end" }
        ],
        "header": [
          { "element": { "type": "text", "content": "Beschreibung" } },
          { "element": { "type": "text", "content": "Betrag" } }
        ],
        "rows": [
          {
            "$each": "invoice.items",
            "template": [
              { "element": { "type": "text", "content": "{{description}}" } },
              { "element": { "type": "text", "content": "{{amount}}" } }
            ]
          }
        ]
      },
      {
        "type": "text",
        "content": "Gesamtsumme: {{invoice.total}}",
        "style": { "font": "sans-bold" }
      }
    ]
  }
}

// examples/invoice-data.json
{
  "invoice": {
    "number": "RE-2026-0100",
    "total": "1.200,00 €",
    "items": [
      { "description": "Beratung Softwarearchitektur", "amount": "1.000,00 €" },
      { "description": "Reisekosten", "amount": "200,00 €" }
    ]
  },
  "customer": {
    "name": "Acme Software GmbH"
  }
}
  • CLI
  • JSON
  • Template