Skip to main content
Lifetime license included with every purchase
n8n workflowsinvoice generationPDF automationbilling

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.

Nn8n Marketplace Team·July 14, 2026·Updated July 14, 2026·6 min read

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

NodePurpose
Webhook / Schedule TriggerFires on order completion or on a batch run
CodeIncrements the counter, builds the invoice HTML
HTTP RequestPosts HTML to Gotenberg, returns a PDF binary
Google Drive / S3Stores the PDF under a predictable path
GmailAttaches and emails the invoice
Google SheetsAppends the invoice to the register

Getting Started

  1. Stand up a Gotenberg container alongside your n8n instance.
  2. Build the counter Code node and test that two quick runs produce consecutive numbers.
  3. Write the HTML-building Code node with your branding and a sample line-item payload.
  4. Wire the HTTP Request to Gotenberg and confirm you get a PDF binary back.
  5. Add the Drive store and the Gmail send; check the attachment opens.
  6. Append the register row and verify it matches the stored file.
  7. 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
Skip the build

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.

Get the LTD Launch & Fulfillment Automator

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
FAQ

Common questions

How do I generate an invoice PDF in n8n without a paid service?
Build the invoice as HTML in a Code node, then convert it with a self-hosted Gotenberg or wkhtmltopdf endpoint called from an HTTP Request node. That keeps the PDF generation on your own infrastructure instead of routing customer billing data through a third-party document API you pay per call.
How do I assign sequential invoice numbers in n8n?
Store the last number in n8n's workflow static data or a single-cell Google Sheet, read it at the start of the run, increment it, and write it back before generating the PDF. Never derive the number from a timestamp or a random ID. Tax authorities expect a gapless sequence, and a random ID fails an audit.
Can n8n store generated invoices and email them automatically?
Yes. After the PDF is built, a Google Drive or S3 node files it under the customer and the invoice number, and a Gmail node attaches it to the customer email. Append a row to a register sheet in the same run so finance has a searchable ledger of every invoice issued.
Stop reading. Start running.

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.

Free — $40 value

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