Free guide
Automate invoice data extraction with n8n and AI OCR
Automating data extraction from invoices has become a key challenge for freelancers, accountants and SMEs wishing to save time on administrative processing, reduce manual errors and easily centralize their receipts.
Thanks to n8n a visual automation platform, and an artificial intelligence-based OCR engine, it's now possible to automatically extract information from PDF invoices or receipts: amount, VAT, date, supplier, product lines, etc.
This step-by-step training course shows you how to set up a complete workflow: from automatic document retrieval to structuring and exporting documents to an accounting tool such as Excel, Google Sheets or Airtable.
Examples of use cases:
- Automated extraction of luncheon vouchers for expense reports
- Reading supplier receipts for accounting filing
- Creation of a table for tracking customer invoices with VAT
1. Preparing invoices for automation
1.1 Centralize your documents
For automation to work reliably, it's advisable to group all invoices and receipts in a central location. The easiest options to integrate with n8n are:
- Google Drive
- Dropbox
- Amazon S3
- FTP / WebDAV
1.2 Supported formats
OCR engines generally accept the following formats:
- PDF (ideal for invoices)
- JPG / PNG (useful for scanned receipts or photos)
Avoid complex or hybrid formats (scanned PDF with partial vector content).
1.3 Best practices
- Use sufficient resolution: 300 DPI recommended
- Avoid blurred or badly-framed documents
- Add a clear naming system (e.g.:
facture_fournisseur_2024-05.pdf) - Sort files by monthly folder or supplier to facilitate batch processing
2. Trigger workflow in n8n
To start invoice processing automatically, you need to define a starting point (trigger) in n8n. Two main methods are possible:
2.1 Manual triggering (test or one-off mode)
Ideal for testing purposes or for users who prefer to manually drop a file into a folder:
- Create a Manual Trigger in n8n
- Start processing manually each time a document is added
2.2 Automatic triggering (in production)
To fully automate the import of new files, use a trigger linked to an external source such as:
- Google Drive: with the node
Google Drive → Watch Files - Dropbox: with the node
Dropbox → Watch Files - Webhook: if another tool or form can send the file
2.3 Concrete example: monitoring a Drive folder
In this case, the trigger will detect the addition of a new PDF:
- Add node Google Drive → Watch Files
- Configure OAuth2 authentication with your Google Account
- Specify the folder to watch
- Choose "Only Files" mode and "Added" type
Each new file automatically triggers the OCR analysis workflow.
3. Download and convert files for analysis
Before sending a document to an OCR engine, you need to retrieve it from its source (Google Drive, Dropbox, etc.) and convert it to base64 if the OCR API doesn't take URLs directly.
3.1 Downloading the file from the source
Depending on the platform used, n8n offers native nodes to retrieve the file:
- Google Drive → Download: from the ID transmitted by the trigger
- Dropbox → Download File
- Webhook or API: to receive a file from another tool
This node will return the document in binaryready for processing.
3.2 Converting to base64
The majority of OCR APIs, like that of Mistral require the document to be base64 encoded in the HTTP call.
Here is an example of conversion in n8n with a node Function:
// Récupération des données binaires du fichier PDF
const binaryData = items[0].binary.data;
let base64Data = '';
// Extraction du contenu base64
if (binaryData) {
base64Data = binaryData.data;
// Sortie propre au format JSON
items = [
{
json: {
data: base64Data
}
}
];
}
return items;
The result is a variable {{$json["data"]}} containing the base64-encoded document, ready to be used in the OCR API call.
💡 Tip
You can also rename the key in the JSON return if you want to call it something else (e.g. pdf_base64), or directly concatenate the string data:application/pdf;base64, at this stage if requested by API.
4. Calling an AI OCR engine
Once the PDF file has been converted to base64, it's time to send it to an artificial intelligence-based OCR engine to extract readable data.
4.1 Why not use OpenAI or Sora?
Although generalist models such as OpenAI GPT or Sora are capable of reading text or image files, they pose many problems when submitting structured documents such as invoices:
- They rewrite sentences and modify line headings
- They can forget entire lines or truncate after a certain number of elements
- They sometimes misinterpret amounts, dates or invoice numbers
Result: erroneous data that cannot be used for reliable accounting.
4.2 Using Mistral OCR for reliable extraction
The solution recommended here in 2025 is the use of the Mistral OCR engine, which offers an API dedicated to the analysis of documents such as invoices or receipts. But in the years to come, I have no doubt that the OpenAI and SORA models will be able to do this with ease!
The model used is mistral-ocr-latestand works equally well with PDFs and base64 images (JPG/PNG).
Example of an API call from n8n (via HTTP Request)
This is the structure to be used in a node HTTP Request in n8n:
{
"method": "POST",
"url": "https://api.mistral.ai/v1/ocr",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer {{YOUR_MISTRAL_API_KEY}}"
},
"body": {
"model": "mistral-ocr-latest",
"document": {
"type": "document_url",
"document_url": "data:application/pdf;base64,{{$json[\"data\"]}}"
},
"include_image_base64": true
},
"options": {
"bodyContentType": "json"
}
}
Important information: the URL must contain the complete string data:application/pdf;base64, followed by the base64 content returned by the previous node.
4.3 For image format (meal voucher, photo of expense report)
If you process an image file (JPG, PNG), the structure changes slightly:
{
"model": "mistral-ocr-latest",
"document": {
"type": "image_url",
"image_url": "data:image/jpeg;base64,{{$json[\"data\"]}}"
}
}
In this case, remember to adapt the MIME type: image/jpeg or image/png.
Expected result
The engine returns a JSON object containing the plain text, separated by page, and in a format that's easy to parse or restructure. It generally recognizes:
- Name of customer and supplier
- Product or service lines
- Totals, VAT, date and invoice number
In our tests, Mistral succeeded in extracting 100 % of the lines from a 3-page PDF invoice without loss or alteration of headings or amounts.
5. Clean and structure data extracted by OCR
Once the OCR API response has been retrieved, the text can be long, structured by pages, and sometimes difficult to use as is. It is therefore essential to clean and restructure it.
5.1 Collate OCR text (multi-page)
OCR engines (like Mistral) often return a table with one entry per page. To reconstruct a single complete text:
- Add a node Split Out to split out each page
- Using a node Edit Fields or Set to target only useful content (eg:
markdown,text,raw) - Add a node Merge / Combine or Summarize with the
concatenateoption to collect texts
5.2 Example of Markdown merge in n8n
// Dans un nœud Function
return [{
json: {
fullText: items.map(i => i.json.markdown).join('\n\n')
}
}];
This code creates a single field fullText with the full content of the OCR document.
5.3 Clean data structuring (using LLM)
Once the text has been compiled, it may be useful to transform into a structured table (e.g. customer name, product table, total excl. tax, VAT, etc.).
To do this, add a LLM Agent or Basic LLM Chain in n8n, linked to a model like:
- Anthropic Claude (ideal for structuring without hallucinating)
- Mistral instruct
- OpenAI GPT-4 (in very strict mode with clear instructions)
🎯 System prompt example
Tu es un assistant expert en structuration de documents.
Ne modifie pas le contenu fourni. Ton objectif est uniquement de structurer les données.
Retourne :
1. Les informations du client et de la société (nom, adresse, SIRET, etc.)
2. Un tableau des prestations ou produits (désignation, quantité, prix unitaire, total)
3. Les totaux (HT, TVA, TTC), numéro de facture, date, IBAN si présent
Format attendu : Markdown clair et exploitable.
The result can then be used as is or transformed into a table for export.
6. Export to Excel, Google Sheets or an accounting tool
Once the data has been extracted and structured, the next step is to store it in a format that can be used for accounting or analysis.
6.1 Export to Google Sheets
Google Sheets is easy to integrate with n8n, allowing you to create tables for tracking invoices or expense reports.
- Add a node Google Sheets → Append Row
- Connect to your Google account via OAuth2
- Specify sheet ID and target tab
- Map columns (date, customer, amount, VAT, etc.) to extracted JSON fields
💡 Tip: you can also create a tab by month or by supplier for better organization.
6.2 Export to Excel (via OneDrive or local)
If you use Excel instead of Google Sheets:
- You can go through Microsoft Excel Online (OneDrive) with native integration
- Or export data in
.csvvia a node Spreadsheet File or Function - Finally, send the file by email or save it on a shared drive.
6.3 Connection to ERP or accounting software
If you work with an accounting management tool or an ERP, it is often possible to:
- Use a REST API to push data
- Automate the import of a CSV file into the software
- Create invoice "drafts" in ERP with OCRized information
Compatible tools include:
- QuickBooks
- Sage Business Cloud
- Odoo
- Axonaut, Indy, Dougs, Pennylane...
💡 Bonus: automatic generation of PDF files or emails
You can also generate:
- A PDF summary of the extracted data
- Automatic email with invoice summary (e.g. for the accounting department)
n8n offers nodes such as PDF Generator, Send Email or HTML to PDF.
7. Enhancements and advanced cases
Once the main workflow is in place, additional steps can be added to improve reliability, automate accounting classification or avoid duplication.
7.1 Duplicate invoice detection
To avoid recording the same invoice twice, you can:
- Check whether the invoice number or the total amount already exists in your database
- Query Google Sheets, Airtable or a database before insertion
- Add a condition in n8n (node IF) to block export in case of duplication
7.2 Automatic classification of expenses
You can have extracted invoices automatically classified in accounting categories, for example:
- Meals (luncheon vouchers, bars, cafés)
- Transport (gas, tickets, tolls)
- Supplies (office equipment, software)
To do this, add an LLM or Set node with conditional logic based on invoice content (description, supplier, amount).
7.3 VAT extraction and validation
The amount of VAT is crucial for accounting:
- If explicitly mentioned, extract it with a regex or LLM
- Alternatively, you can recalculate it from the amounts excluding and including tax.
- Checks its consistency before recording (e.g. rate at 5.5 %, 10 %, 20 %...).
7.4 Integration into an approval process
For companies with several employees, you can create an approval system:
- Send an email or Slack with the extracted info
- Wait for manual validation or a click on a link
- Export only if the receipt is "validated
7.5 Batch processing
You can also process several files at once:
- Monitoring of an entire folder containing 10 to 100 invoices
- Loop For Each to analyze them one by one
- Generation of a single consolidated output table