All blogs
Extract Invoice Data Like a Pro: Turn PDFs into Structured Gold with OCR + AI (No Accountant Required!)
Let's be honest: manually typing invoice data feels like using a typewriter in 2025. You know there's a better way, but figuring it out seems harder than explaining cryptocurrency to your grandparents.
But here's the good news: with Diaflow's visual automation and a dash of AI magic, you can turn any PDF invoice into perfectly structured data in under 10 minutes. No spreadsheet gymnastics required.
Perfect for:
- Finance teams are drowning in paper invoices
- Bookkeepers who dream of automation (and more coffee breaks)
- Anyone who thinks data entry is about as fun as watching paint dry
Let's build this invoice-crushing machine. Pinky promise, it's easier than it sounds.
Why Invoice OCR Matters (Spoiler: Your Sanity Will Thank You)
You could keep manually typing invoice details into spreadsheets. You could also travel by horse and buggy, but why would you?
The average finance team processes hundreds of invoices monthly. Each one takes 5-10 minutes to input manually. That's hours of mind-numbing data entry that could be spent on, well, literally anything else.
With automated OCR extraction, you go from "ugh, another stack of invoices" to "watch me process 50 invoices while I grab lunch."
What You'll Build
A 6-step Diaflow automation that works like magic:
- You upload a PDF invoice
- System converts it to text AND images (because AI is picky like that)
- GPT-4o-mini reads everything and extracts structured data
- Results get saved to a clean database table
- You get perfectly formatted invoice data
- You do a little happy dance (optional but recommended)
Let's make it happen.
Step 1: Set Up Your Invoice Trigger
Head to your Diaflow dashboard and create a new flow. This time, we're starting with a File trigger because we need to catch those PDF invoices.

Here's the setup:
- Click the Trigger node
- Select "File upload" as your trigger type
- Set the file description to: "Please upload the original invoice in PDF format. One file per upload. Only official VAT invoices from suppliers are supported."
- Set required -> you don't want to waste your credit just to process nothing
Think of this as your digital receptionist – politely asking for the right documents and refusing anything that doesn't belong (sorry, cat photos don't count as invoices).
Step 2: Convert PDF to Text (The Translation Layer)
Add a "Document to Plain text" node and connect it to your trigger.

Configuration:
- Input Data: Select trigger.file
This step is like having a really fast reader scan your entire invoice and type out everything they see. The AI will use this text as reference material later, because even smart AI needs good notes.
Step 3: Turn PDF into Images (Because AI Has Eyes Too)
Next, drag in a "PDF to Image" node. Yes, we're converting the same PDF twice – once to text, once to images. Think of it as giving the AI both reading glasses AND regular vision.

Settings:
- Input File: Choose trigger.file
- Pages per image: Set to 2 (adjust based on your invoice length)
Why both text AND images? Simple: OCR might miss some details that are crystal clear in the visual format. We're covering all our bases here.
Step 4: The AI Magic Happens (GPT-4o-mini Time!)
This is where things get exciting. Add an OpenAI node and select the GPT-4o-mini model. Now comes the fun part – crafting the perfect prompt.

Copy this prompt (it's pre-tested and battle-ready):
## You are a smart accounting assistant that extracts structured accounting data from international invoices.
## You will receive:
- An image of the invoice
- The OCR-extracted plaintext from the invoice
## Your task:
- Use both the image and the OCR plaintext to extract structured accounting data into an array of JSON records.
- Each record must correspond to a single line item, and it must contain **both the line item fields** and **the shared invoice metadata**.
---
## Language Handling:
- You may receive invoices in different languages, such as Vietnamese, English, or others.
- Detect the invoice language from the OCR text or image context.
- Apply appropriate field-mapping heuristics (e.g., "Tax Code" = "Mã số thuế" in Vietnamese, "VAT Number" in English).
---
## Format & Accuracy Rules:
- Dates must be formatted as `"YYYY-MM-DD"`.
- All currency and numeric fields (amounts, unit prices, tax, bank account numbers, etc.) must prioritize the **OCR text** over image interpretation.
- The `"Payment Account Number"` and `"Payment Bank Name"` must be the bank account of the **buyer**, i.e., the entity making the payment. Do not use the vendor's account details.
- The `"Description"` field refers to the whole invoice and must be the **same across all line items**. For example: "Buy from [Name of Vendor]".
- If a field is not available or cannot be determined, return it as `null`.
---
## Output:
- Return **ONLY** a valid JSON array of flat objects.
- Do **NOT** include quotes, markdown, code formatting, or explanation.
---
### OCR Extracted Text:
"""
{{dtt-0.output}}
"""
### JSON Output Format:
[
{
"Invoice Number": null,
"Invoice Date": null,
"Document Date": null,
"Due Date": null,
"Vendor Name": null,
"Vendor Tax ID": null,
"Vendor Address": null,
"Vendor Phone": null,
"Vendor Email": null,
"Vendor Bank Account": null,
"Vendor Bank Name": null,
"Buyer Name": null,
"Buyer Tax ID": null,
"Buyer Address": null,
"Buyer Phone": null,
"Buyer Email": null,
"Payment Account Number": null,
"Payment Bank Name": null,
"Purchase Order Number": null,
"Sales Order Number": null,
"Contract Number": null,
"Delivery Note Number": null,
"Payment Method": null,
"Payment Terms": null,
"Description": null,
"Currency": null,
"Exchange Rate": null,
"Item Code": null,
"Item Name": null,
"Item Description": null,
"Quantity": null,
"Unit Price": null,
"Unit of Measure": null,
"Tax Rate": null,
"Tax Amount": null
}
]
Important settings:
- Image source: Connect to pdf-img-0.output (from your PDF to Image step)
- Reference the OCR text using {{dtt-0.output}}
This prompt is basically giving the AI a PhD in accounting and invoice reading. It knows exactly what to look for, how to format it, and even handles multiple languages. Pretty neat, right?
Step 5: Save Your Data Gold (Diaflow Tables)
Add a "Diaflow Tables" node to store your extracted data. This is where your beautiful, structured invoice data gets a permanent home.

Configuration options:
- Action: Choose "Insert data" to save new records
- Create a new table or select an existing one
- Input: Connect to openai-0.output (your structured JSON data)
Think of this as your digital filing cabinet – except it's organized, searchable, and won't get lost when someone "reorganizes" the office.
Step 6: Show Off Your Results (Output Node)
Finally, add an Output node to display your success. Configure it to show the extracted data in a clean, readable format.

Display options:
- Show the JSON data from Diaflow Tables
- Format as a nice table view
- Add a success message (because victories should be celebrated!)
Connect the Dots
Your workflow should flow like this: File Trigger → Document to Text → PDF to Image → OpenAI → Diaflow Tables → Output

Each step feeds into the next, creating a smooth pipeline from messy PDF to structured data paradise.
Test Drive Your Invoice Machine
Time for the moment of truth! Upload a sample PDF invoice and watch the magic happen:
- Your PDF gets uploaded
- Text extraction happens in seconds
- Images are generated for AI analysis
- GPT-4o-mini works its data extraction magic
- Clean, structured data gets saved to your table
- You see beautiful results on screen
The whole process takes about 30 seconds. Compare that to 10 minutes of manual data entry, and you've just become 20x more efficient. Not bad for a day's work!

Why This Changes Everything
Instead of spending hours squinting at invoice details and playing "hunt the tax number," you now have a smart assistant that never gets tired, never makes typos, and works 24/7.
Want to process invoices from your email? Add an email trigger. Need to validate extracted data? Add condition nodes. Want to send results to your accounting software? Diaflow plays nice with APIs and integrations.
This isn't just automation – it's liberation from the data entry dungeon.
Wrapping It Up
Invoice processing doesn't have to be painful. With Diaflow's visual automation and AI-powered extraction, you can transform stacks of PDFs into structured data faster than you can say "expense report."
Try it, tweak it, and watch your finance team's productivity soar. Because life's too short for manual data entry, and your time is worth way more than typing invoice numbers.
Ready to turn your invoices into data gold? Start building now and join the ranks of teams who've automated their way to accounting nirvana.

How Diaflow Transforms Invoice Processing with Smart Automation
Diaflow: Your Gateway to Effortless Invoice Management
At Diaflow, we believe that repetitive tasks like invoice data entry should be automated, not endured. As demonstrated in this tutorial, Diaflow combines powerful OCR technology with AI to transform your PDF invoices into clean, structured data in minutes, not hours.
By automating the entire extraction process, Diaflow empowers finance teams, bookkeepers, and business owners to eliminate manual data entry while maintaining accuracy and compliance. Whether you're processing dozens or hundreds of invoices monthly, Diaflow scales with your business needs, turning tedious paperwork into streamlined digital workflows.
Stop wrestling with invoice data and start focusing on what matters – growing your business. With Diaflow's visual automation platform, professional invoice processing is just a few clicks away. Transform your financial operations today and discover why thousands of teams trust Diaflow to handle their most important business processes.