{
  "name": "Invoice PDF (CustomJS)",
  "nodes": [
    {
      "parameters": {},
      "id": "a1b2c3d4-0001-4000-8000-000000000001",
      "name": "When clicking 'Execute workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [-220, 0]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1000000-0000-4000-8000-000000000001",
              "name": "invoiceNumber",
              "value": "INV-2026-0042",
              "type": "string"
            },
            {
              "id": "f1000000-0000-4000-8000-000000000002",
              "name": "issueDate",
              "value": "2026-11-27",
              "type": "string"
            },
            {
              "id": "f1000000-0000-4000-8000-000000000003",
              "name": "dueDate",
              "value": "2026-12-27",
              "type": "string"
            },
            {
              "id": "f1000000-0000-4000-8000-000000000004",
              "name": "customerName",
              "value": "Northwind Trading Ltd.",
              "type": "string"
            },
            {
              "id": "f1000000-0000-4000-8000-000000000005",
              "name": "customerAddress",
              "value": "48 Harbour Road\nBristol BS1 5TY\nUnited Kingdom",
              "type": "string"
            },
            {
              "id": "f1000000-0000-4000-8000-000000000006",
              "name": "currency",
              "value": "EUR",
              "type": "string"
            },
            {
              "id": "f1000000-0000-4000-8000-000000000007",
              "name": "items",
              "value": "={{ [{\"description\":\"Implementation workshop\",\"quantity\":2,\"unitPrice\":850},{\"description\":\"Workflow migration\",\"quantity\":1,\"unitPrice\":1400},{\"description\":\"Support retainer, December\",\"quantity\":1,\"unitPrice\":320}] }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0002-4000-8000-000000000002",
      "name": "Invoice data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [0, 0]
    },
    {
      "parameters": {
        "resource": "convert",
        "operation": "htmlToPdf",
        "html": "=<!DOCTYPE html>\n<html>\n  <head>\n    <meta charset=\"utf-8\" />\n    <style>\n      * { box-sizing: border-box; }\n      body { font-family: Helvetica, Arial, sans-serif; color: #111827; margin: 0; padding: 48px; font-size: 13px; }\n      .top { display: flex; justify-content: space-between; align-items: flex-start; }\n      h1 { font-size: 28px; margin: 0 0 4px; letter-spacing: -0.02em; }\n      .muted { color: #6b7280; }\n      .meta { text-align: right; line-height: 1.7; }\n      .parties { margin-top: 40px; }\n      .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: #6b7280; margin-bottom: 6px; }\n      table { width: 100%; border-collapse: collapse; margin-top: 36px; }\n      th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: #6b7280; border-bottom: 1px solid #e5e7eb; padding: 0 0 10px; }\n      th.num, td.num { text-align: right; }\n      td { padding: 12px 0; border-bottom: 1px solid #f3f4f6; }\n      .totals { margin-top: 24px; margin-left: auto; width: 260px; }\n      .totals div { display: flex; justify-content: space-between; padding: 6px 0; }\n      .totals .grand { border-top: 2px solid #111827; margin-top: 8px; padding-top: 12px; font-size: 16px; font-weight: 700; }\n      footer { margin-top: 56px; padding-top: 16px; border-top: 1px solid #e5e7eb; font-size: 11px; color: #6b7280; }\n    </style>\n  </head>\n  <body>\n    <div class=\"top\">\n      <div>\n        <h1>Invoice</h1>\n        <div class=\"muted\">{{ $json.invoiceNumber }}</div>\n      </div>\n      <div class=\"meta\">\n        <div><strong>Your Company</strong></div>\n        <div class=\"muted\">Issued {{ $json.issueDate }}</div>\n        <div class=\"muted\">Due {{ $json.dueDate }}</div>\n      </div>\n    </div>\n\n    <div class=\"parties\">\n      <div class=\"label\">Bill to</div>\n      <div><strong>{{ $json.customerName }}</strong></div>\n      <div class=\"muted\">{{ $json.customerAddress.replace(/\\n/g, '<br />') }}</div>\n    </div>\n\n    <table>\n      <thead>\n        <tr>\n          <th>Description</th>\n          <th class=\"num\">Qty</th>\n          <th class=\"num\">Unit price</th>\n          <th class=\"num\">Amount</th>\n        </tr>\n      </thead>\n      <tbody>\n        {{ $json.items.map(i => `<tr><td>${i.description}</td><td class=\"num\">${i.quantity}</td><td class=\"num\">${i.unitPrice.toFixed(2)}</td><td class=\"num\">${(i.quantity * i.unitPrice).toFixed(2)}</td></tr>`).join('') }}\n      </tbody>\n    </table>\n\n    <div class=\"totals\">\n      <div><span class=\"muted\">Subtotal</span><span>{{ $json.items.reduce((s, i) => s + i.quantity * i.unitPrice, 0).toFixed(2) }} {{ $json.currency }}</span></div>\n      <div><span class=\"muted\">VAT 19%</span><span>{{ ($json.items.reduce((s, i) => s + i.quantity * i.unitPrice, 0) * 0.19).toFixed(2) }} {{ $json.currency }}</span></div>\n      <div class=\"grand\"><span>Total</span><span>{{ ($json.items.reduce((s, i) => s + i.quantity * i.unitPrice, 0) * 1.19).toFixed(2) }} {{ $json.currency }}</span></div>\n    </div>\n\n    <footer>\n      Payment due by {{ $json.dueDate }}. Please reference {{ $json.invoiceNumber }} with your transfer.\n    </footer>\n  </body>\n</html>"
      },
      "id": "a1b2c3d4-0003-4000-8000-000000000003",
      "name": "Invoice to PDF",
      "type": "@custom-js/n8n-nodes-pdf-toolkit-v2.pdfToolkit",
      "typeVersion": 1,
      "position": [220, 0]
    }
  ],
  "connections": {
    "When clicking 'Execute workflow'": {
      "main": [[{ "node": "Invoice data", "type": "main", "index": 0 }]]
    },
    "Invoice data": {
      "main": [[{ "node": "Invoice to PDF", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "pinData": {},
  "meta": { "templateCredsSetupCompleted": false }
}
