Build an Invoice Generation Workflow in n8n
Build an n8n invoice generation workflow that creates a PDF, assigns a sequential invoice ID, stores it, and emails the customer. No paid add-ons required.
Invoicing Is a Sequence Problem, Not a Design Problem
Generating an invoice looks like a formatting job: make it pretty, drop in the line items, export a PDF. The part that actually matters is boring. The number. Invoices need a gapless, sequential ID, because that's what an auditor checks first, and that's the bit a quick script gets wrong by reaching for a timestamp or a UUID.
An n8n invoice generation workflow gets the sequence right and automates the rest: read the next number, build the document, render a PDF, store it, email the customer, log it to a register. No manual numbering, no paid document SaaS in the middle of your billing data.
This is the generation side of invoicing. The chasing-for-payment side is a different workflow, and worth keeping separate.
What You Can Automate
- Sequential numbering: read, increment, and persist a gapless invoice ID every run
- PDF rendering: HTML invoice converted to PDF on your own Gotenberg instance
- Customer storage: each PDF filed in Drive or S3 under customer and invoice number
- Auto-email: the invoice attached and sent the moment it's generated
- Register logging: a row appended to a master sheet for finance to search
- Trigger flexibility: fire from a webhook on order completion, a new Stripe charge, or a sheet row
The Invoice Pipeline
A complete generation flow runs in one pass, and the numbering bookends it:
Trigger (webhook / new order)
→ Code (read + increment invoice counter, write it back)
→ Code (build invoice HTML from line items)
→ HTTP Request (HTML → PDF via Gotenberg)
→ Google Drive (store PDF under customer/INV-0042.pdf)
→ Gmail (attach PDF, send to customer)
→ Google Sheets (append register row)
Read-increment-persist happens first so the number is locked before anything can fail downstream. If the email bounces, you still issued a valid, numbered, stored invoice.
1. Trigger and number
Whatever fires the workflow, the first real step is the counter. Read the last invoice number from static data or a single-cell sheet, add one, write it back immediately. Doing the write-back first matters: if two orders land close together, you don't want both to read the same number. In practice a queue-mode n8n with a single worker on this workflow avoids the race entirely.
2. Build the document
A Code node assembles the invoice HTML from the line items in the trigger payload: customer block, itemized table, subtotal, tax, total, the invoice number and date. Keep it as a template string with your branding. HTML is easier to maintain than a binary template and renders to PDF cleanly.
3. Render the PDF
Call a self-hosted Gotenberg or wkhtmltopdf endpoint from an HTTP Request node, posting the HTML and getting back a PDF binary. This keeps customer billing data on infrastructure you control. The paid document APIs work, but routing every invoice through a metered third party is a cost and a data-handling question you don't need to take on.
4. Store
A Google Drive or S3 node writes the PDF binary under a predictable path: customer folder, INV-0042.pdf. Predictable paths make the register's links resolvable and make a future reconciliation job trivial.
5. Send and log
Gmail attaches the PDF and sends it. Then append a register row — number, customer, amount, date, storage link — so finance has a ledger without opening Drive. That register is also what a later payment-chase workflow reads from.
Implementation Patterns
Pattern 1 — Persist the counter before you generate. The gapless sequence is the whole compliance story. Read, increment, and write back the counter as the first action, not the last. If PDF rendering fails, you've burned a number, and a small gap with a logged reason beats two invoices sharing an ID. Self-hosted n8n lets you run this workflow on a single worker so the counter never races.
Pattern 2 — Self-host the PDF step. Customer billing data shouldn't transit a third-party document service you pay per render. A Gotenberg container next to your n8n instance renders HTML to PDF for free and keeps the data in your perimeter. One more service to run, but billing data is exactly the data you want to keep close.
Pattern 3 — Register as source of truth. The append-to-sheet step isn't an afterthought. It's the ledger every downstream finance workflow reads: the payment chaser, the monthly reconciliation, the tax export. Write a complete row every time, even when the email fails, so the register never disagrees with reality.
n8n Nodes You'll Use Most
| Node | Purpose |
|---|---|
| Webhook / Schedule Trigger | Fires on order completion or on a batch run |
| Code | Increments the counter, builds the invoice HTML |
| HTTP Request | Posts HTML to Gotenberg, returns a PDF binary |
| Google Drive / S3 | Stores the PDF under a predictable path |
| Gmail | Attaches and emails the invoice |
| Google Sheets | Appends the invoice to the register |
Getting Started
- Stand up a Gotenberg container alongside your n8n instance.
- Build the counter Code node and test that two quick runs produce consecutive numbers.
- Write the HTML-building Code node with your branding and a sample line-item payload.
- Wire the HTTP Request to Gotenberg and confirm you get a PDF binary back.
- Add the Drive store and the Gmail send; check the attachment opens.
- Append the register row and verify it matches the stored file.
- Connect your real trigger and run one live order end to end.
For sellers fulfilling lifetime deals or one-off purchases, the LTD Launch & Fulfillment Automator wires this generate-store-send flow into the post-purchase sequence so the invoice goes out as part of fulfillment, not as a separate chore.
See the LTD Launch & Fulfillment Automator →The LTD Launch & Fulfillment Automator ships this as part of fulfillment: the purchase trigger, the document generation and storage, and the customer email already wired, so a new order produces a numbered invoice and delivery without a manual step. It's part of The Complete n8n Templates Bundle, a one-time lifetime license to the whole catalog (plus every template added later) if you run more than one of these billing automations.
Generating the invoice is half the job; getting paid is the other half. Once invoices are issued, automating invoice reminders with n8n walks the escalation ladder from gentle nudge to final notice, and the broader n8n invoice automation guide covers the payment-matching side. The InvoiceChase template reads the same register this workflow writes.
Browse the full template catalog →Common questions
How do I generate an invoice PDF in n8n without a paid service?
How do I assign sequential invoice numbers in n8n?
Can n8n store generated invoices and email them automatically?
Get the workflow templates this guide is built on
Import-ready n8n JSON, step-by-step setup, and tested end-to-end. One-time payment, own it forever.
Get 3 tested n8n templates, free
The full customer package for three real catalog templates — workflow JSON, step-by-step setup guide, credential checklist. Built through the same live-instance release process as everything we sell. Plus new templates and automation guides in your inbox. No spam, unsubscribe anytime.
- 01Smart To-Do List ManagerPre-built n8n workflow template that automates productivity with OpenAI. Live in about 10 minutes.$14
- 02Email Follow-Up AutomatorPre-built n8n workflow template that automates crm with OpenAI. Live in about 15 minutes.$12
- 03Market Trend AnalyzerPre-built n8n workflow template that automates data processing with OpenAI. Live in about 10 minutes.$14
More automation guides

n8n Backup Automation That Actually Verifies the Backup
A Backup You Never Verified Is a Coin Flip Every n8n backup automation tutorial that ranks does the same thing: schedule an export, push the JSON to Google Drive or S3, done. They back up the data and…

How to Build an n8n Log Alerting Workflow (No Grafana Required)
Most n8n Error Setups Tell You Everything, Which Means They Tell You Nothing An n8n log alerting workflow has one job: surface the failures that need a human and quietly file the ones that don't. The…

n8n Uptime Monitoring with Slack Alerts (Without the Alert Storms)
An Uptime Check That Cries Wolf Gets Muted in a Week The point of n8n uptime monitoring with Slack alerts isn't to detect a single outage. It's to be trusted the next hundred times it fires. Most of t…