{
  "id": "",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Merge all PDFs from a Google Drive folder with generated title pages and watermark using Autype",
  "tags": [],
  "nodes": [
    {
      "id": "4e134e76-8b7d-485e-b68e-26742beae619",
      "name": "Run Workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -560,
        128
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "8150627a-44f8-40fe-b367-c91cfee2fc6d",
      "name": "List PDFs in Folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -320,
        128
      ],
      "parameters": {
        "filter": {
          "folderId": {
            "__rl": true,
            "mode": "id",
            "value": "YOUR_FOLDER_ID"
          }
        },
        "options": {
          "fields": [
            "*"
          ]
        },
        "resource": "fileFolder",
        "returnAll": true
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "4e1a39a2-b607-43e2-a6db-c401a6021ba7",
      "name": "Build Title Pages JSON",
      "type": "n8n-nodes-base.code",
      "position": [
        -80,
        128
      ],
      "parameters": {
        "jsCode": "const files = $input.all().map(i => i.json);\n\nconst sections = files.map((file, index) => ({\n  type: 'page',\n  align: 'center',\n  content: [\n    {\n      type: 'h1',\n      text: file.name.replace(/\\.pdf$/i, ''),\n      fontSize: 28,\n      color: '#1a1a1a'\n    },\n    {\n      type: 'text',\n      text: ' '\n    },\n    {\n      type: 'text',\n      text: `Created: ${file.createdTime ? new Date(file.createdTime).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }) : 'Unknown'}`,\n      fontSize: 14,\n      color: '#555555'\n    },\n    {\n      type: 'text',\n      text: `Last Modified: ${file.modifiedTime ? new Date(file.modifiedTime).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }) : 'Unknown'}`,\n      fontSize: 14,\n      color: '#555555'\n    },\n    {\n      type: 'text',\n      text: `Owner: ${file.owners && file.owners[0] ? file.owners[0].displayName : 'Unknown'}`,\n      fontSize: 14,\n      color: '#555555'\n    },\n    {\n      type: 'text',\n      text: `Document ${index + 1} of ${files.length}`,\n      fontSize: 12,\n      color: '#999999'\n    }\n  ]\n}));\n\nconst config = {\n  document: { type: 'pdf', size: 'A4' },\n  sections\n};\n\nreturn [{\n  json: {\n    config: JSON.stringify(config),\n    files: files.map((f, i) => ({ id: f.id, name: f.name, index: i }))\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "8b1072a9-f029-469e-976d-626a004b9cdf",
      "name": "Render Title Pages PDF",
      "type": "n8n-nodes-autype.autype",
      "position": [
        160,
        128
      ],
      "parameters": {
        "config": "={{ $json.config }}",
        "downloadOutput": true,
        "additionalFields": {}
      },
      "credentials": {
        "autypeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4a104ef5-2c17-43be-8714-1cf82c721247",
      "name": "Prepare Loop Items",
      "type": "n8n-nodes-base.code",
      "position": [
        576,
        128
      ],
      "parameters": {
        "jsCode": "const titlePagesFileId = $input.first().json.id;\nconst files = $('Build Title Pages JSON').first().json.files;\n\nreturn files.map((file, index) => ({\n  json: {\n    driveFileId: file.id,\n    fileName: file.name,\n    titlePageNumber: index + 1,\n    titlePagesFileId\n  }\n}));"
      },
      "typeVersion": 2
    },
    {
      "id": "63b3a4fd-934e-42be-891d-a739754d75fb",
      "name": "Loop Over Documents",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        768,
        128
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "c681fbb2-c13f-42aa-bad4-49f9fffaf3ab",
      "name": "Download PDF from Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1008,
        224
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.driveFileId }}"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "076f31fa-88ea-415e-90fd-398e7143f5f2",
      "name": "Upload Document to Autype",
      "type": "n8n-nodes-autype.autype",
      "position": [
        1248,
        224
      ],
      "parameters": {
        "resource": "file"
      },
      "credentials": {
        "autypeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d9274e8c-63a2-458e-b345-36bff5e86805",
      "name": "Extract Title Page",
      "type": "n8n-nodes-autype.autype",
      "position": [
        1488,
        224
      ],
      "parameters": {
        "pages": "={{ $('Loop Over Documents').item.json.titlePageNumber.toString() }}",
        "fileId": "={{ $('Loop Over Documents').item.json.titlePagesFileId }}",
        "resource": "documentTools",
        "operation": "pages"
      },
      "credentials": {
        "autypeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "200b57c5-9e1b-458d-bc8a-4ba429bcd4eb",
      "name": "Collect Merge Pair",
      "type": "n8n-nodes-base.code",
      "position": [
        1728,
        224
      ],
      "parameters": {
        "jsCode": "const titlePageFileId = $json.outputFileId\nconst docFileId = $('Upload Document to Autype').item.json.id;\nconst fileName = $('Loop Over Documents').item.json.fileName;\n\nreturn [{\n  json: {\n    titlePageFileId,\n    docFileId,\n    fileName\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "dfc3c022-b648-42d7-8893-cbd6fbfbb76f",
      "name": "Build Final Merge List",
      "type": "n8n-nodes-base.code",
      "position": [
        1008,
        -144
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nconst fileIds = [];\n\nfor (const item of items) {\n  fileIds.push(item.json.titlePageFileId);\n  fileIds.push(item.json.docFileId);\n}\n\nreturn [{ json: { fileIds: fileIds.join(',') } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "6b33fa02-ec93-425a-a0b5-48eeda174bc6",
      "name": "Merge All PDFs",
      "type": "n8n-nodes-autype.autype",
      "position": [
        1248,
        -144
      ],
      "parameters": {
        "fileIds": "={{ $json.fileIds }}",
        "resource": "documentTools"
      },
      "credentials": {
        "autypeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6f37f228-0540-4677-85bd-18ce47e15fc7",
      "name": "Add Company Watermark",
      "type": "n8n-nodes-autype.autype",
      "position": [
        1456,
        -144
      ],
      "parameters": {
        "text": "Your Company Name",
        "fileId": "={{ $('Merge All PDFs').item.json.outputFileId }}",
        "resource": "documentTools",
        "operation": "watermark",
        "downloadOutput": true,
        "watermarkOptions": {
          "color": "#2563EB",
          "opacity": 0.6,
          "fontSize": 14,
          "rotation": 45
        }
      },
      "credentials": {
        "autypeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2f181d44-a882-4297-8514-d7d52fdc51e1",
      "name": "Save Final PDF to Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1680,
        -144
      ],
      "parameters": {
        "name": "=merged-documents-{{ $now.format('yyyy-MM-dd') }}.pdf",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_FOLDER_ID"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "4054763c-74c8-4369-a40d-82c6e437a04c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -976,
        -832
      ],
      "parameters": {
        "width": 560,
        "height": 1128,
        "content": "## Merge All PDFs from Google Drive with Generated Title Pages and Watermark\n### This workflow reads every PDF from a Google Drive folder, generates a title page for each document (showing name, dates, and owner), merges everything into a single PDF with interleaved title pages, adds a company watermark, and uploads the result back to Drive.\n\nClick \"Test Workflow\" to run it once. Each document gets a professional cover sheet before its content.\n\n### How it works\n1. **List PDFs in Folder** \u2014 Searches a Google Drive folder for all PDF files.\n2. **Build Title Pages JSON** \u2014 A Code node creates an Autype Render JSON config with one page section per document (name, created date, modified date, owner, document number).\n3. **Render Title Pages PDF** \u2014 Autype renders all title pages as a single multi-page PDF in one API call.\n4. **Upload Title Pages PDF** \u2014 Uploads the rendered PDF to Autype Tools for page extraction.\n5. **Loop Over Documents** \u2014 For each PDF:\n   - Downloads from Google Drive\n   - Uploads to Autype Tools\n   - Extracts the corresponding title page from the title pages PDF\n   - Collects the title page file ID and document file ID as a merge pair\n6. **Build Final Merge List** \u2014 Interleaves file IDs: title page 1, doc 1, title page 2, doc 2, etc.\n7. **Merge All PDFs** \u2014 Combines everything into one document in order.\n8. **Add Company Watermark** \u2014 Stamps the company name in blue on every page (top-right area, 60% opacity).\n9. **Save Final PDF to Drive** \u2014 Uploads the result as `merged-documents-YYYY-MM-DD.pdf` to the same Google Drive folder.\n\n### Requirements\n* **Autype account** \u2014 Sign up at [app.autype.com](https://app.autype.com) and go to **Settings \u2192 API Keys** to generate your API key.\n* **Google Drive** \u2014 Connect your Google account via OAuth2 in n8n credentials.\n* **n8n-nodes-autype** \u2014 Install the Autype community node via **Settings \u2192 Community Nodes** in your self-hosted n8n instance.\n\n> \u26a0\ufe0f Community node: requires self-hosted n8n. Not available on n8n Cloud."
      },
      "typeVersion": 1
    },
    {
      "id": "ab4dc91b-9646-4a51-bacf-621e9e69ff9a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -368,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 700,
        "height": 348,
        "content": "### 1. List & Generate Title Pages\nSearches the Google Drive folder for all PDFs. A Code node builds the Autype Render JSON with one title page section per document. Autype renders all title pages in a single API call as one multi-page PDF."
      },
      "typeVersion": 1
    },
    {
      "id": "1dadec4d-7472-4c42-b387-2caa94b4dfba",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        976,
        80
      ],
      "parameters": {
        "color": 7,
        "width": 908,
        "height": 316,
        "content": "### 2. Loop: Download, Upload, Extract Title Page\nFor each document: download from Drive, upload to Autype, extract the matching title page (by page number) from the title pages PDF, and collect both file IDs as a merge pair."
      },
      "typeVersion": 1
    },
    {
      "id": "37e287d7-76c4-4f92-90be-88ce05a7da5e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        976,
        -240
      ],
      "parameters": {
        "color": 7,
        "width": 908,
        "height": 268,
        "content": "### 3. Merge, Watermark & Save\nAfter the loop, file IDs are interleaved (title1, doc1, title2, doc2...) and merged into one PDF. A blue company-name watermark is added to every page. The final PDF is uploaded to Google Drive."
      },
      "typeVersion": 1
    },
    {
      "id": "cac87ec3-79ab-4067-ad80-10be4b4ab95b",
      "name": "Upload Title Pages PDF",
      "type": "n8n-nodes-autype.autype",
      "position": [
        368,
        128
      ],
      "parameters": {
        "resource": "file"
      },
      "credentials": {
        "autypeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "autype-drive-example-id",
  "connections": {
    "Run Workflow": {
      "main": [
        [
          {
            "node": "List PDFs in Folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge All PDFs": {
      "main": [
        [
          {
            "node": "Add Company Watermark",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collect Merge Pair": {
      "main": [
        [
          {
            "node": "Loop Over Documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Title Page": {
      "main": [
        [
          {
            "node": "Collect Merge Pair",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Loop Items": {
      "main": [
        [
          {
            "node": "Loop Over Documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List PDFs in Folder": {
      "main": [
        [
          {
            "node": "Build Title Pages JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Documents": {
      "main": [
        [
          {
            "node": "Build Final Merge List",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download PDF from Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Company Watermark": {
      "main": [
        [
          {
            "node": "Save Final PDF to Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Final Merge List": {
      "main": [
        [
          {
            "node": "Merge All PDFs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Title Pages JSON": {
      "main": [
        [
          {
            "node": "Render Title Pages PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Render Title Pages PDF": {
      "main": [
        [
          {
            "node": "Upload Title Pages PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Title Pages PDF": {
      "main": [
        [
          {
            "node": "Prepare Loop Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download PDF from Drive": {
      "main": [
        [
          {
            "node": "Upload Document to Autype",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Document to Autype": {
      "main": [
        [
          {
            "node": "Extract Title Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}