{
  "name": "Generate Monthly Report PDFs in n8n",
  "nodes": [
    {
      "parameters": {},
      "id": "trigger",
      "name": "When clicking Execute",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Replace this node with whatever already holds your data.\n// The field names below are what the template reads.\nreturn [{ json: {\n    \"reportTitle\": \"Acquisition report\",\n    \"period\": \"November 2026\",\n    \"generatedAt\": \"1 Dec 2026, 06:00\",\n    \"summary\": \"Signups grew 18 percent against October, driven almost entirely by organic search. Paid spend was flat and its conversion rate fell slightly, which is worth a look before the December budget is set.\",\n    \"account\": {\n      \"name\": \"Acme Retail BV\",\n      \"owner\": \"Prepared for Jules Berger\"\n    },\n    \"kpis\": [\n      {\n        \"label\": \"Sessions\",\n        \"value\": \"48,210\",\n        \"change\": \"+12.4% vs Oct\",\n        \"color\": \"#047857\"\n      },\n      {\n        \"label\": \"Signups\",\n        \"value\": \"1,284\",\n        \"change\": \"+18.1% vs Oct\",\n        \"color\": \"#047857\"\n      },\n      {\n        \"label\": \"Conversion\",\n        \"value\": \"2.66%\",\n        \"change\": \"+0.12pp\",\n        \"color\": \"#047857\"\n      },\n      {\n        \"label\": \"Cost per signup\",\n        \"value\": \"EUR 9.40\",\n        \"change\": \"-4.1%\",\n        \"color\": \"#047857\"\n      }\n    ],\n    \"channels\": [\n      {\n        \"name\": \"Organic search\",\n        \"sessions\": \"26,440\",\n        \"signups\": \"812\",\n        \"rate\": \"3.07%\"\n      },\n      {\n        \"name\": \"Paid search\",\n        \"sessions\": \"11,920\",\n        \"signups\": \"271\",\n        \"rate\": \"2.27%\"\n      },\n      {\n        \"name\": \"Referral\",\n        \"sessions\": \"6,180\",\n        \"signups\": \"142\",\n        \"rate\": \"2.30%\"\n      },\n      {\n        \"name\": \"Direct\",\n        \"sessions\": \"3,670\",\n        \"signups\": \"59\",\n        \"rate\": \"1.61%\"\n      }\n    ],\n    \"notes\": [\n      \"Two long tail pages published in October now account for 9 percent of organic signups.\",\n      \"Paid search conversion dropped after the 14 Nov bid change, worth reverting as a test.\",\n      \"Referral traffic is one partner. Treat the number as concentrated, not diversified.\"\n    ]\n  } }];"
      },
      "id": "report-data",
      "name": "Report data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "resource": "convert",
        "operation": "htmlToPdf",
        "html": "=<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"utf-8\" />\n  <title>Monthly report, {{ $json.period }}</title>\n  <style>\n    * { box-sizing: border-box; }\n    body {\n      margin: 0;\n      padding: 18mm 16mm;\n      font-family: Inter, Arial, Helvetica, sans-serif;\n      font-size: 10.5pt;\n      color: #111827;\n      line-height: 1.5;\n    }\n    h1 { font-size: 22pt; margin: 0; letter-spacing: -0.02em; }\n    h2 { font-size: 12pt; margin: 0 0 6px; }\n    .muted { color: #6b7280; }\n    .small { font-size: 9pt; }\n    .row { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }\n    .label { font-size: 8pt; text-transform: uppercase; letter-spacing: 0.08em; color: #6b7280; margin-bottom: 4px; }\n    .rule { border: 0; border-top: 1px solid #e5e7eb; margin: 20px 0; }\n    table { width: 100%; border-collapse: collapse; }\n    th {\n      text-align: left;\n      font-size: 8pt;\n      text-transform: uppercase;\n      letter-spacing: 0.08em;\n      color: #6b7280;\n      border-bottom: 1px solid #e5e7eb;\n      padding: 0 0 8px;\n    }\n    td { padding: 9px 0; border-bottom: 1px solid #f3f4f6; vertical-align: top; }\n    .num { text-align: right; white-space: nowrap; }\n    .totals { margin-top: 18px; margin-left: auto; width: 55%; }\n    .totals td { border: 0; padding: 4px 0; }\n    .grand td { border-top: 2px solid #111827; padding-top: 10px; font-weight: 700; font-size: 12pt; }\n    .badge { display: inline-block; padding: 4px 10px; border-radius: 999px; background: #eef2ff; color: #4338ca; font-size: 8pt; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }\n    .foot { position: fixed; bottom: 10mm; left: 16mm; right: 16mm; font-size: 8pt; color: #9ca3af; border-top: 1px solid #f3f4f6; padding-top: 6px; }\n    @media print {\n      tr { page-break-inside: avoid; }\n      thead { display: table-header-group; }\n    }\n  </style>\n</head>\n<body>\n<div class=\"row\">\n  <div>\n    <span class=\"badge\">{{ $json.period }}</span>\n    <h1 style=\"margin-top:10px\">{{ $json.reportTitle }}</h1>\n    <div class=\"muted\">{{ $json.account.name }}</div>\n  </div>\n  <div class=\"num small muted\">\n    <div>Generated {{ $json.generatedAt }}</div>\n    <div>{{ $json.account.owner }}</div>\n  </div>\n</div>\n\n<hr class=\"rule\" />\n\n<div class=\"row\" style=\"gap:12px\">\n  {{ $json.kpis.map(kpi => `\n  <div style=\"flex:1;border:1px solid #e5e7eb;border-radius:8px;padding:12px\">\n    <div class=\"label\">${kpi.label}</div>\n    <div style=\"font-size:18pt;font-weight:700\">${kpi.value}</div>\n    <div class=\"small\" style=\"color:${kpi.color}\">${kpi.change}</div>\n  </div>\n  `).join('') }}\n</div>\n\n<h2 style=\"margin-top:26px\">Summary</h2>\n<p>{{ $json.summary }}</p>\n\n<h2 style=\"margin-top:24px\">By channel</h2>\n<table>\n  <thead>\n    <tr>\n      <th>Channel</th>\n      <th class=\"num\">Sessions</th>\n      <th class=\"num\">Signups</th>\n      <th class=\"num\">Rate</th>\n    </tr>\n  </thead>\n  <tbody>\n    {{ $json.channels.map(row => `\n    <tr>\n      <td>${row.name}</td>\n      <td class=\"num\">${row.sessions}</td>\n      <td class=\"num\">${row.signups}</td>\n      <td class=\"num\">${row.rate}</td>\n    </tr>\n    `).join('') }}\n  </tbody>\n</table>\n\n<h2 style=\"margin-top:24px\">Notes</h2>\n<ul>\n  {{ $json.notes.map(note => `\n  <li style=\"margin-bottom:6px\">${note}</li>\n  `).join('') }}\n</ul>\n\n<div class=\"foot\">{{ $json.account.name }} · {{ $json.period }} · page 1</div>\n</body>\n</html>",
        "outputFilenamePdf": "report-pdf-n8n.pdf"
      },
      "id": "render-the-report",
      "name": "Render the report",
      "type": "@custom-js/n8n-nodes-pdf-toolkit-v2.pdfToolkit",
      "typeVersion": 1,
      "position": [
        440,
        0
      ],
      "credentials": {
        "customJsApi": {
          "id": "1",
          "name": "CustomJS account"
        }
      }
    }
  ],
  "connections": {
    "When clicking Execute": {
      "main": [
        [
          {
            "node": "Report data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Report data": {
      "main": [
        [
          {
            "node": "Render the report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
