n8n OCR Tutorial: Extract Text from Scanned PDFs and Images Automatically

Scanned documents are where data goes to die. An invoice arrives as a photo, a contract comes in as a flattened PDF, a receipt is a blurry phone snapshot — and every one of them has to be read by a human and retyped into a system before it's useful. That retyping is slow, error-prone, and completely automatable.

OCR (optical character recognition) turns pixels back into text, and modern vision models take it further by understanding which text is the invoice total versus the tax line. This tutorial walks through building an end-to-end OCR-to-structured-data pipeline in n8n.

OCR vs. AI vision: what's the difference?

Classic OCR gives you a raw wall of characters — accurate, but with no idea what any of it means. Vision-capable LLMs read the same document and understand its structure, so you can ask 'return the vendor name, invoice number, and total as JSON' and get exactly that. For structured extraction, the AI-vision approach saves you a mountain of parsing logic.

Step 1: Get the file into n8n

Trigger on the source: an email attachment, a Google Drive upload, a webhook from a form, or a photo dropped into a chat. Read the binary file into the workflow so it's ready to send to your OCR or vision node.

Step 2: Handle multi-page PDFs

A scanned PDF is often many pages. Split it into individual page images first so each page gets clean processing, then reassemble the extracted fields at the end. Skipping this step is the number-one reason OCR pipelines return garbage on long documents.

Step 3: Extract with a precise prompt

Send each page to a vision model with an explicit schema:

Extract the following fields as JSON: vendor, date (ISO 8601), invoice_number, line_items[], subtotal, tax, total. If a field is missing, use null. Return only JSON.

A tight schema is what turns a paragraph of prose into a row you can insert into a database.

⚡ Skip the build — grab the ready-made template

Skip the OCR plumbing — this template ingests any PDF or image, extracts the fields you care about, and returns clean structured JSON ready for your database.

Get "AI PDF Extractor" on Gumroad — $39 →

Step 4: Validate before you trust it

Add a sanity check: do the line items sum to the subtotal? Is the date plausible? Is the total a number, not text? Route anything that fails validation to a human-review queue instead of pushing bad data downstream. Automation without validation just moves errors faster.

Step 5: Write structured data where it belongs

Push the clean JSON to its destination — Airtable, Google Sheets, your accounting tool, a database. Now a stack of scanned documents becomes a searchable, sortable table, and the retyping job disappears.

Frequently asked questions

Does this work on handwriting?

Vision models handle clear printed text extremely well and can manage some neat handwriting, but messy handwriting still benefits from a human-review step. Always keep the validation gate for low-confidence extractions.

Can it process hundreds of documents a day?

Yes. Batch the files, add a short delay between calls to respect API rate limits, and the pipeline scales to whatever volume your document backlog throws at it.

Ready to automate this?

You can wire this together yourself with the steps above, or install a battle-tested version in minutes. The AI PDF Extractor template ships with the full n8n workflow JSON, setup notes, and sample credentials so you can import, plug in your keys, and go live today.

Ready to automate? Get this template on Gumroad → ($39)