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](https://www.notion.so/Simple-sample-template-Template-Link-22b3f8a1e57f8070beacd034ba6f557f?pvs=4) --- ### B. Import the Workflow into n8n ```bash 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: - **DocAgent**—*System Prompt* (top) - **User Choice Match Check**—*System Prompt* (top) Save. > Why manual? Caching the list saves API 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.gs**—*File – 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*
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)
- Template Discovery The TemplateList node scans the Drive folder you specify via the
?mode=metaendpoint and returns anid / title / desclist. The bot shows this list in chat. - 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. - Data-Collection Loop - The bot asks for every placeholder value. - For each conditional block it asks Yes / No. Answers are accumulated in a
dataJSON object. - Final Confirmation The bot summarizes the inputs—when the user clicks Confirm, the DocProcess sub-workflow starts.
- 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 |
- Delivery The master agent sends Download PDF & Open Google Doc links.
- Error Paths -
status:ERROR, missing:[]—bot lists missing fields and re-asks. -unknown:[]—template list is outdated; rerun TemplateList. - Any Apps Script error—the returnedmessageis 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
- Open Template List node – replace
%3CYOUR_PARENT_ID%3E in parentswith the real folder ID in the URL. - Right-click node > Execute Node.
- Copy the entire JSON response.
- In the editor paste it into: - DocAgent—System Prompt (top) - User Choice Match Check—System Prompt (top) Save. > Why manual? Caching the list saves API 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.gs—File – 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 buyers can create an account from the cart to unlock a controlled $10 first-purchase credit on eligible orders of $25+.
Secure checkout powered by Stripe
Support
How to import this workflow into n8n
- 1Purchase or download the workflow to get the n8n workflow JSON file.
- 2In your n8n instance, open Workflows and choose "Import from File" (or paste the JSON with Ctrl+V on the canvas).
- 3Open each node marked with a credential warning and connect your own accounts and API keys.
- 4Run the workflow once manually to verify the data flow, then toggle it to Active.
Related File & Document Management workflows
- Automate Invoice Data Extraction to Airtable with OCR and AI$14.99
- Save new Gmail attachments to Google Drive$3.99
- Automate PDF Invoice Creation from Google Sheets Using PDF.co$4.99
- Automatically Save and Organize Outlook Email Attachments in OneDrive Folders$9.99
- Automate Invoice Data Extraction from Google Drive to Google Sheets with Mistral OCR$14.99
- Convert Files to Markdown with Datalab.to API in n8n$9.99
Need this deployed? We'll set it up for you.
Our automation experts deploy this workflow in your stack, connect your accounts, and verify it works — or build a custom solution from scratch.