The shape of the problem
An invoice email is a small, well-defined document: a supplier, an invoice number, a date, a currency, a net amount, a tax amount and a total. The difficulty is not reading one of them — it is that the same invoice arrives more than once: forwarded, re-sent, copied to a second mailbox, or delivered again after a mail rule misfires. A pipeline that appends whatever it sees double-counts spend, and a ledger you cannot trust is worse than a spreadsheet you keep by hand.
So the workflow has four stages, and the last one is the point: trigger on a message with a PDF attached, get the text layer out, parse the fields and check the arithmetic, then write the row only if it is not already there.
Step 1 — trigger on mail, not on the inbox
Two triggers work, and the choice is about which mailbox you have.
Gmail Trigger
One event, Message Received, fired at the poll time you choose. The parameters that matter, as documented:1
- Max Emails per Poll — default 10, maximum 50. Anything above the limit is queued for the next poll cycle, not dropped.
- Search — Gmail search syntax, so
has:attachment filename:pdfnarrows the trigger before your workflow spends any execution time on it. Both operators are Google's own.2 - Label Names or IDs — if your supplier invoices already carry a label, trigger on the label instead of on a search.
- Read Status — unread only by default. Switch it to include read mail if you are back-filling.
- Simplify — on by default, and that matters: the simplified response is message IDs, labels and headers only.3 You fetch the message itself to reach the attachment.
IMAP Email trigger
Works with any mailbox that speaks IMAP, which is what most self-hosters actually have, and it is what the free preview workflow in this project uses. Three settings on that node decide what happens to your mail, and all three are documented:5
- Action — None leaves the message unread; Mark as Read marks it read when n8n receives it. It is a choice, not a fixed behaviour. If it is set to Mark as Read and a later node fails, that mail is not picked up again by itself, so a failed execution needs a human look.
- Download Attachments — the docs describe it as a toggle and suggest leaving it off unless you need it, because it increases processing. An invoice workflow needs it on.
- Format — Resolved returns the full email with attachments as binary data; Simple does not gather inline attachments.
A dedicated mailbox, or a folder rule, is the cheapest way to keep this out of your working inbox. Attachments, collisions and read flags have a page of their own.
Step 2 — get the text layer out of the PDF
The Extract From File node takes a binary file and turns it into JSON. The operation you want is Extract From PDF.4
This reads the text layer — the characters a PDF stores for searching and copying. It does not do OCR. A scan, a phone photo, or a PDF exported from a print-to-PDF printer at low quality has no text layer, and the extraction returns little or nothing. That is not a bug to work around with a bigger model; it is a different problem with a different cost.
If your PDFs come from suppliers' accounting systems — which is most of them — the text layer is there and this step is instant.
Step 3 — parse, and make the arithmetic prove itself
A Code node with plain regular expressions is enough, and anyone who reads JavaScript can inspect it. The patterns that cover most supplier layouts look for:
- the invoice number — the token after a label such as
Invoice,Invoice no,Rechnungsnummer,Facture,Fattura; require at least one digit so a word like "invoice" cannot match; - dates — three numeric groups with a separator, plus month names; decide day-first or month-first per supplier rather than guessing per document;
- amounts — digits with an optional thousands separator and a decimal part, plus the currency token if one is present;
- labels for net, tax and total —
Net,Subtotal,VAT,Tax,Total,Amount due, and their local equivalents where you have them.
Then the check that catches most bad parses without any AI:
const ok = Math.abs((net + vat) - total) <= 0.02;
If net plus tax does not equal the total within a cent or two, the parser has read at least one of the three numbers wrong. The free starter workflow in this project does exactly this check and reports the failure in plain words rather than writing a wrong row.
Write down what you could not read. Every row should carry
a status and a reason string. The paid pack uses four: ok,
needs_review (either the arithmetic failed or the fields could not be read at all —
the reason column says which), duplicate and possible_duplicate. A
ledger where "missing" and "wrong" look the same is worse than one that admits both.
Step 4 — three duplicate checks, in this order
The order matters, because each check is more permissive than the one before it.
- Exact. Same supplier and same invoice number as a row already in the
ledger →
duplicate, not written. This catches the forward, the re-send and the second mailbox. - Probable. Same supplier, same total, within a short window (21 days is a
reasonable default), but a different invoice number →
possible_duplicate, written but excluded from totals until a human confirms. This catches the supplier who re-issues under a new number without crediting the old one. - Arithmetic. A total that fails
net + vat→needs_review, regardless of whether it is a duplicate, because a misparse and a duplicate are different problems and you want to see both.
Idempotency is the test: run the workflow twice over the same mailbox and the CSV must be byte-identical after the second run. If a timestamp or a run ID lands in the file, that test will never pass and the file stops being diffable.
One more case worth deciding in advance: a corrected re-issue. Same invoice number, corrected amount. Check 1 classes it as a duplicate and the wrong amount stays. Either accept editing the row by hand, or key the ledger on supplier + number + version and accept a slightly messier file. Decide deliberately; do not discover it at quarter end.
Start with one invoice, not with the mailbox
Before any of the above touches a real inbox, read a single PDF and look at what came back.
The free starter in this project does exactly that: a form upload, the extraction, the parse,
the arithmetic check, and a plain answer — no credential, no ledger, nothing written. It is the
file free-01-read-one-invoice.json on the
free workflows page (the same starter is
on n8n.io), next to
free-03-check-invoice-csv-duplicates.json, which runs two of the three
checks above over a CSV you already have: the exact one (same supplier, same number) and
the probable one (same supplier, same date and total). The arithmetic check lives in
free-01, and the "same supplier and amount under a different number" rule is only
in the paid pack.
Then the mailbox preview, free-02-inbox-preview.json, which reads and reports
but writes nothing.
If the free starter reads your suppliers' invoices correctly, the pack will too — it is the same parser. If it does not, USD 49 will not fix that, and the 14-day fix-or-refund in the terms exists precisely for the case where it does not: we first try to fix it, and refund if we cannot.
Where to run it
The three free starters write nothing, so they run on n8n Cloud as they are — start n8n Cloud. The ledger itself writes CSV files into the instance's own folder, and n8n documents no way to reach or keep that folder on Cloud: the documented Cloud backup route exports workflows, not the instance directory.6 That is why the paid pack is documented as self-hosted. On Cloud the file nodes would have to become a storage node — and you maintain that.
Honest limits
- No OCR. Scans and phone photos return empty fields. What OCR costs, and what it sends off your server: the OCR guide.
- Several invoices inside one PDF (a monthly statement): the patterns find the first invoice number and the last total, which is a wrong row. Split those files first.
- Ambiguous dates are read day-first unless you tell it otherwise; amounts
with three decimal places are misread; a bare
$is assumed to be USD unless an ISO code appears. - Non-Latin scripts are untested in the parser this project ships. Latin-1 accents are handled.
- Execution history keeps the extracted text. n8n saves execution data for 336 hours by default, which is a second copy of your invoices on your own disk. The disk and execution history guide explains how to change or shorten that.
- What was actually tested here: the core template ran end to end on n8n 2.44.4 with four PDF invoices, twice — the first run booked three and kept one duplicate out; the second classified all four as duplicates and left the ledger byte-identical. That is not a month of your suppliers' invoices, and the site says so on the front page too.
Troubleshooting
- Extraction returns almost nothing. The PDF has no text layer — a scan, a phone photo, or a bad print-to-PDF. Open the file and try to select its text to confirm; nothing in this pipeline can read a picture.
- The trigger never fires. On Gmail, check the Search filter, the Read Status setting, and the 10-messages-per-poll default (maximum 50). On IMAP, check the Mailbox Name — a folder rule may be moving invoices elsewhere.
- An invoice is booked twice. The key is supplier plus invoice number as
text: "ACME GmbH" and "Acme Gmbh", or
INV-118andINV 118, produce two keys. Normalise both before comparing. A row flaggedpossible_duplicateis meant to sit outside the totals until a human confirms it.
The eleven-workflow version
The pack adds the parts a business needs after the first working pipeline: the review queue for rows that need a human, approval requests over a threshold with a callback that records the decision, bank reconciliation against the ledger, a duplicate-payment alert, a VAT quarter summary, currency normalisation, an accounting export, a monthly close pack, and a nightly dated copy of the ledger.
Invoice Ledger — 11 workflows, USD 49
One business, one purchase, 14-day fix-or-refund if it does not import or cannot read your invoices. What is in it, in detail.
Sources
- n8n docs — Gmail Trigger (Message Received event; Max Emails per Poll default 10, maximum 50; Search, Label, Read Status, Simplify). Read 2026-10-22.
- Gmail Help — Refine searches in Gmail (
has:andfilename:operators). Read 2026-10-22. - n8n docs — Gmail message operations (Simplify returns metadata only: IDs, labels and headers). Read 2026-10-22.
- n8n docs — Extract From File (operation “Extract From PDF” converts a binary file to JSON). Read 2026-10-22.
- n8n docs — IMAP Email node (Mark as Read: None or Mark as Read; Download Attachments toggle and its processing cost; Format Resolved versus Simple). Read 2026-10-22.
- n8n docs — Download workflows (n8n Cloud) (the documented Cloud backup is a workflow download from the admin dashboard, not the instance folder). Read 2026-10-22.