{
  "id": "fgDemoDocs001",
  "name": "Fork Guy SAMPLE - document-pdf",
  "active": false,
  "nodes": [
    {
      "parameters": {},
      "id": "manual",
      "name": "Run demo manually",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return [{json:{\"template\":\"PROJECT SUMMARY\\n\\nClient: {{client_name}}\\nService: {{service}}\\nScope: {{scope}}\\n\\nThis fictional project brief demonstrates placeholder replacement.\\nIt is not a contract, invoice or record of client work.\\n\\nGoogle Docs integration: not connected\\nDrive storage: simulated\\nEmail delivery: not sent\",\"values\":{\"client_name\":\"Alex Example\",\"service\":\"Sample website setup\",\"scope\":\"One demonstration landing page\"}}}];"
      },
      "id": "fixture",
      "name": "Fictional fixture",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        0
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const input = $input.first().json;\nconst fields = ['client_name', 'service', 'scope'];\nconst values = {};\nfor (const key of fields) {\n  const value = input.values?.[key];\n  if (typeof value !== 'string' || !value.trim() || value.length > 160 || /[^\\x20-\\x7e]/.test(value)) throw new Error(`Invalid demo field: ${key}`);\n  values[key] = value.trim();\n}\nif (typeof input.template !== 'string' || input.template.length > 4000) throw new Error('Invalid demo template');\n// Build the Google Docs replacement body WITHOUT sending it to Google.\nconst requests = fields.map(key => ({replaceAllText:{containsText:{text:`{{${key}}}`,matchCase:true},replaceText:values[key]}}));\n// Single pass: supplied text cannot introduce more template substitutions.\nconst text = input.template.replace(/\\{\\{([^{}]+)\\}\\}/g, (_, key) => {\n  if (!Object.hasOwn(values, key)) throw new Error(`Unknown placeholder: ${key}`);\n  return values[key];\n});\nif (text.includes('{{') || text.includes('}}')) throw new Error('Unresolved template token');\nif (/[^\\x20-\\x7e\\n]/.test(text)) throw new Error('Demo PDF supports ASCII text only');\nconst lines = text.split('\\n').flatMap(line => {\n  if (line.length > 85) throw new Error('Demo line too long; split the template line');\n  return [line];\n});\nif (lines.length > 22) throw new Error('Demo is limited to one page');\nconst escape = s => s.replace(/\\\\/g,'\\\\\\\\').replace(/\\(/g,'\\\\(').replace(/\\)/g,'\\\\)');\nconst stream = '1 1 1 rg 0 0 612 792 re f\\n0 0.45 0.28 rg 44 708 524 4 re f\\nBT /F1 22 Tf 44 743 Td (FORK GUY / SAMPLE REPORT) Tj ET\\n0.04 0.06 0.05 rg\\nBT /F1 11 Tf 44 674 Td 23 TL\\n'+lines.map((line,i)=>(i?'T* ':'')+`(${escape(line)}) Tj`).join('\\n')+'\\nET\\n0 0.45 0.28 rg BT /F1 10 Tf 44 56 Td (Fictional data | Local renderer | No Google account connected) Tj ET\\n';\nconst objects = [\n '<< /Type /Catalog /Pages 2 0 R >>',\n '<< /Type /Pages /Kids [3 0 R] /Count 1 >>',\n '<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << /Font << /F1 4 0 R >> >> /Contents 5 0 R >>',\n '<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>',\n `<< /Length ${Buffer.byteLength(stream,'ascii')} >>\\nstream\\n${stream}endstream`\n];\nlet pdf = '%PDF-1.4\\n';const offsets=[0];\nobjects.forEach((obj,i)=>{offsets.push(Buffer.byteLength(pdf,'ascii'));pdf+=`${i+1} 0 obj\\n${obj}\\nendobj\\n`;});\nconst start=Buffer.byteLength(pdf,'ascii');\npdf+=`xref\\n0 ${objects.length+1}\\n0000000000 65535 f \\n`+offsets.slice(1).map(n=>String(n).padStart(10,'0')+' 00000 n \\n').join('')+`trailer\\n<< /Size ${objects.length+1} /Root 1 0 R >>\\nstartxref\\n${start}\\n%%EOF\\n`;\nreturn [{json:{demonstration:true,googleConnected:false,mergedText:text,googleDocsBatchUpdate:{requests},storage:{status:'simulated',filename:'sample-project-summary.pdf'},delivery:{status:'not-sent'}},binary:{data:{data:Buffer.from(pdf,'ascii').toString('base64'),mimeType:'application/pdf',fileName:'sample-project-summary.pdf'}}}];\n"
      },
      "id": "logic",
      "name": "Merge fields - Render local PDF",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        0
      ]
    }
  ],
  "connections": {
    "Run demo manually": {
      "main": [
        [
          {
            "node": "Fictional fixture",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fictional fixture": {
      "main": [
        [
          {
            "node": "Merge fields - Render local PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
