> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://support.pdfgeneratorapi.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Advanced Automation: Creating Conditional Invoices with n8n and Google Sheets

This guide is a follow-up to our basic article, "[How to integrate PDF Generator API with n8n](https://support.pdfgeneratorapi.com/en/article/how-to-integrate-pdf-generator-api-with-n8n-zulhli/)". While the first article covered the fundamentals of generating a document, this tutorial will teach you how to build a "smart" workflow.

### Our Goal: To create an automated system that:

1. Triggers when a new row is added to a Google Sheet.
2. Intelligently chooses between two different PDF templates based on the data in the row.
3. Generates the correct invoice as a PDF.
4. Emails the invoice to the customer.
5. Saves a copy of the invoice to a specific Google Drive folder.

![Final workflow](https://storage.crisp.chat/users/helpdesk/website/-/1/1/e/0/11e0e518fc48ce00/image_1iq4zmv.png)

### **Prerequisites**

Before you begin, please ensure you have the following ready:

* **A working n8n instance:** This workflow runs perfectly on both n8n cloud and a local setup.
* **PDF Generator API Account:** You will need at least **two different invoice templates** created in your account (e.g., a "Standard Invoice" and a "Pro Invoice").
* **Google Account Credentials:** You must have credentials for Google Sheets, Gmail, and Google Drive connected to your n8n instance. *Remember to create separate credentials for each Google service.*
* **A Google Sheet:** This will be our data source. Create a new sheet with (minimum) columns like `Customer_Name`, `Email`, `Invoice_Number`, and `Type`.

### Step 1: The Foundation - Preparing Your Data

The key to this entire workflow is the "trigger" column in your Google Sheet. For this example, we'll use the `Type` column. This column will contain either the word "Standard" or "Pro" to tell n8n which template to use.

### Step 2: Building the Workflow - Trigger and Logic

**Node 1: Google Sheets Trigger**
* Add a **Google Sheets** node to your canvas.
* Configure it to trigger **On Row Added** and point it to the sheet you just created.
* Run a test to ensure it correctly pulls data from your sheet.

**Node 2: The IF Node (The Brain)** This is where the magic happens. The IF node will direct the workflow based on our data.
* Add an **IF** node and connect it to the Google Sheets trigger.
* Set up a condition to check the value from our `Type` column.
* **Condition:** `{{ $json["Type"] }}` | `is equal to` | `Pro`

This creates two output paths: `true` (if the type is "Pro") and `false` (for everything else, which we'll treat as "Standard").

![Logic Node Settings](https://storage.crisp.chat/users/helpdesk/website/-/1/1/e/0/11e0e518fc48ce00/image_sv5gdt.png)


### Step 3: Generating the Correct PDF

Now we'll use our two branches to generate the appropriate document. For detailed guide on how to setup our PDF Generator API Nodes please follow [this article.](https://support.pdfgeneratorapi.com/en/article/how-to-integrate-pdf-generator-api-with-n8n-zulhli/)

**On the `true` path:**
* Add a **PDF Generator API** node.
* Configure it to use your **"Pro Invoice" template**.
* Map the data from the Google Sheets node to your template's fields.

**On the `false` path:**
* Add another **PDF Generator API** node.
* Configure it to use your **"Standard Invoice" template**.
* Map the data just as you did for the "Pro" version.

### Step 4: Handling the Output - The Merge Node

* Add a **Merge** node to your canvas.
* Connect the output*s* of your PDF Generator API nodes to **Input 1 & 2**.
* **Configure the Merge Node:**
     * **Mode**: `Append`
     * **Number of inputs**: `2`

### Step 5: Sending and Archiving the Invoice

With our data correctly merged, the final steps are easy.

**Node 3: Gmail (Send a message)**
* Add a **Gmail** node and connect the Merge node to it.
* **To**: Use an expression to pull the email from the sheet data: `{{ $('Google Sheets Trigger').item.json.Email }}`
* **Attachments**: In the attachments field, specify the name of the property that holds your binary file `{{ $json.filename }}`.

| You can also use available placeholders from left side of your screen (previous steps) in Subject or Message.

![Gmail Node Settings](https://storage.crisp.chat/users/helpdesk/website/-/1/1/e/0/11e0e518fc48ce00/screenshot-2025-10-09-at-15124_dkrht6.png)

**Node 4: Google Drive (Upload file)**
* Add a **Google Drive** node.
* Select Parent **Drive** & **Folder.**
* **File Name**: Create a dynamic name, e.g., `{{ $('Google Sheets Trigger').item.json.Type }}_Invoice_{{ $('Google Sheets Trigger').item.json.Invoice_Number }}`
* **Input Field Name**: Specify the property holding the file. This should be `{{ $json.filename }}`.

![](https://storage.crisp.chat/users/helpdesk/website/-/1/1/e/0/11e0e518fc48ce00/screenshot-2025-10-09-at-15201_1wcm0z9.png)


### Related articles you may find helpful

* [How to embed editor to my application?](https://support.pdfgeneratorapi.com/en/article/how-to-embed-editor-to-my-application-tmxkg5/)
* [How to share templates with other workspaces?](https://support.pdfgeneratorapi.com/en/article/how-to-share-templates-with-other-workspaces-1hq1m2f/)
* [How to use the editor?](https://support.pdfgeneratorapi.com/en/article/how-to-use-the-editor-1a194yy/)

