Skip to main content

Create custom PDF documents from templates with Gemini & Google Drive

Workflow preview

Workflow preview
100%
Create custom PDF documents from templates with Gemini & Google Drive preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

This workflow contains community nodes that are only compatible with the self hosted version of n8n. 1 — What Does It Do / Which Problem Does It Solve? This workflow turns Google Docs based contrac...

Best for

  • Document Extraction automation workflows
  • AI Chatbot automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.lmchatgooglegemini, n8n-nodes-base.httprequesttool, @n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.toolworkflow, @n8n/n8n-nodes-langchain.memorypostgreschat, n8n-nodes-base.httprequest, n8n-nodes-base.stickynote

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Ozgur Karateke.

Original n8n.io source

1.1 Workflow description

Title
Create custom PDF documents from templates with Gemini & Google Drive
Workflow name
Create custom PDF documents from templates with Gemini & Google Drive

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

1 — What Does It Do / Which Problem Does It Solve?

This workflow turns Google Docs-based contract & form templates into ready-to-sign PDFs in minutes—all from a single chat flow.

  • Automates repetitive document creation. Instead of copying a rental, sales, or NDA template and filling it by hand every time, the bot asks for the required values and fills them in.
  • Eliminates human error. It lists every mandatory field so nothing is missed, and removes unnecessary clauses via conditional blocks.
  • Speeds up approvals. The final draft arrives as a direct PDF link—one click to send for signing.
  • One template → unlimited variations. Every new template you drop in Drive is auto-listed with **zero workflow edits—**it scales effortlessly.
  • 100 % no-code. Runs on n8n + Google Apps Script—no extra backend, self-hosted or cloud.

2 — How It Works (Detailed Flow)

  1. 📝 Template Discovery

    📂 The TemplateList node scans the Drive folder you specify via the ?mode=meta endpoint and returns an id / title / desc list. The bot shows this list in chat.

  2. 🎯 Selection & Metadata Fetch

    The user types a template name.

    🔍 GetMetaData opens the chosen Doc, extracts META_JSON, placeholders, and conditional blocks, then lists mandatory & optional fields.

  3. 🗣 Data-Collection Loop

    • The bot asks for every placeholder value.

    • For each conditional block it asks 🟢 Yes / 🔴 No.

      Answers are accumulated in a data JSON object.

  4. Final Confirmation

    The bot summarizes the inputs → when the user clicks Confirm, the DocProcess sub-workflow starts.

  5. ⚙️ DocProcess Sub-Workflow

    🔧 Step Node Task
    1 User Choice Match Check Verifies name–ID match; throws if wrong
    2 GetMetaData (renew) Gets the latest placeholder list
    3 Validate JSON Format Checks for missing / unknown fields
    4 CopyTemplate Copies the Doc via Drive API
    5 FillDocument Apps Script fills placeholders & removes blocks
    6 Generate PDF Link Builds an export?format=pdf URL
  6. 📎 Delivery

    The master agent sends 🔗 Download PDF & ✏️ Open Google Doc links.

  7. 🚫 Error Paths

    • status:"ERROR", missing:[…] → bot lists missing fields and re-asks.
    • unknown:[…] → template list is outdated; rerun TemplateList.
    • Any Apps Script error → the returned message is shown verbatim in chat.

3 — 🚀 Setup Steps (Full Checklist)

> Goal: Get a flawless PDF on the first run. > > > Mentally tick the ☑️ in front of every line as you go. >

☁️ A. Google Drive Preparation

Step Do This Watch Out For
1 Create a Templates/ folder → put every template Doc inside Exactly one folder; no sub-folders
2 Placeholders in every Doc are {{UPPER_CASE}} No Turkish chars or spaces
3 Wrap optional clauses with [[BLOCK_NAME:START]]…[[BLOCK_NAME:END]] The START tag must have a blank line above
4 Add a META_JSON block at the very end Script deletes it automatically after fill
5 Right-click Doc > Details ▸ Description = 1-line human description Shown by the bot in the list
6 Create a second Generated/ folder (for copies) Keeps Drive tidy

> 🔑 Folder ID (long alphanumerical) = <TEMPLATE_PARENT_ID> > > > We’ll paste this into the TemplateList node next. >

Simple sample template → Template Link


🛠 B. Import the Workflow into n8n

Settings ▸ Import Workflow ▸ DocAgent.json

If nodes look Broken afterwards → no community-node problem; you only need to select credentials.


📑 C. Customize the TemplateList Node

  1. Open Template List node ⚙️ → replace

    '%3CYOUR_PARENT_ID%3E' in parents

    with the real folder ID in the URL.

  2. Right-click node > Execute Node.

  3. Copy the entire JSON response.

  4. In the editor paste it into:

    • DocAgentSystem Prompt (top)

    • User Choice Match CheckSystem Prompt (top)

      Save.

> ⚠️ Why manual? Caching the list saves LLM tokens. Whenever you add a template, rerun the node and update the prompts. >


🔗 D. Deploy the Apps Script

Step Screen Note
1 Open Gist files GetMetaData.gs + FillDocument.gsFile ▸ Make a copy Both files may live in one project
2 Project Settings > enable Google Docs API ✔️ & Google Drive API ✔️ Otherwise you’ll see 403 errors
3 Deploy ▸ New deployment ▸ Web app
• Execute as Me
• Who has access Anyone
4 On the consent screen allow scopes:• …/auth/documents…/auth/drive Click Advanced › Go if Google warns
5 Copy the Web App URL (e.g. https://script.google.com/macros/s/ABC123/exec) If this URL changes, update n8n

Apps Script source code → Notion Link


🔧 E. Wire the Script URL in n8n

Node Field Action
GetMetaData URL &lt;WEB_APP_URL&gt;?mode=meta&id={{ $json["id"] }}
FillDocument URL &lt;WEB_APP_URL&gt;

> 💡 Prefer using an .env file? Add GAS_WEBAPP_URL=… and reference it as {{ $env.GAS_WEBAPP_URL }}. >


🔐 F. Add Credentials

  • Google Drive OAuth2Drive API (v3) Full Access
  • Google Docs OAuth2 → same account
  • LLM key (OpenAI / Gemini)
  • (Optional) Postgres Chat Memory credential for the corresponding node

🧪 G. First Run (Smoke Test)

  1. Switch the workflow Active.
  2. In the chat panel type /start.
  3. Bot lists templates → pick one.
  4. Fill mandatory fields, optionally toggle blocks → Confirm.
  5. 🔗 Download PDF link appears → ☑️ setup complete.

❌ H. Common Errors & Fixes

🆘 Error Likely Cause Remedy
403: Apps Script permission denied Web app access set to User Redeploy as Anyone, re-authorize scopes
placeholder validation failed Missing required field Provide the listed values → rerun DocProcess
unknown placeholders: … Template vs. agent mismatch Check placeholder spelling (UPPER_CASE ASCII)
Template ID not found Prompt list is old Rerun TemplateList → update both prompts
Cannot find META_JSON No meta block / wrong tag Add [[META_JSON_START]] … [[META_JSON_END]], retry

✅ Final Checklist

  • Drive folder structure & template rules ready
  • Workflow imported, folder ID set in node
  • TemplateList output pasted into both prompts
  • Apps Script deployed, URL set in nodes
  • OAuth credentials & LLM key configured
  • /start test passes, PDF link received

🙋‍♂️ Need Help with Customizations?

Reach out for consulting & support on LinkedIn: Özgür Karateke

Full Documentation → Notion

Simple sample template → Template Link

Apps Script source code → Notion Link

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Google Gemini Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 2 - GetMetaData

Type / Role
n8n-nodes-base.httpRequestTool - httpRequestTool
Config choices
Version 4.2

Block 3 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 4 - DocAgent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 2

Block 5 - DocProcess

Type / Role
@n8n/n8n-nodes-langchain.toolWorkflow - toolWorkflow
Config choices
Version 2.2

Block 6 - Postgres Chat Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryPostgresChat - memoryPostgresChat
Config choices
Version 1.3

Block 7 - Template List

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 8 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 9 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 10 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 13 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 14 - When Executed by Another Workflow

Type / Role
n8n-nodes-base.executeWorkflowTrigger - executeWorkflowTrigger
Config choices
Version 1.1

Block 15 - If

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 16 - Google Gemini Chat Model1

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 17 - Structured Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserStructured - outputParserStructured
Config choices
Version 1.3

Block 18 - Edit Fields

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 19 - If1

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 20 - Other Errors

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 21 - Switch

Type / Role
n8n-nodes-base.switch - switch
Config choices
Version 3.2

Block 22 - CopyTemplate

Type / Role
n8n-nodes-base.googleDrive - googleDrive
Config choices
Version 3

Block 23 - FillDocument

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 24 - Google Gemini Chat Model2

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Showing the first 24 of 36 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Create custom PDF documents from templates with Gemini & Google Drive
Complexity advanced
Nodes 36
Categories Document Extraction, AI Chatbot
Author Ozgur Karateke
Published 09 Jul 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/5808/5808.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Create custom PDF documents from templates with Gemini & Google Drive do?

This workflow contains community nodes that are only compatible with the self hosted version of n8n. 1 — What Does It Do / Which Problem Does It Solve? This workflow turns Google Docs based contrac...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Document Extraction, AI Chatbot use case.