n8n PDF Processing: Extract, Structure, and Route Documents
Build n8n PDF processing that extracts text, structures it, and routes it anywhere. The Extract from File node, OCR for scans, plus confidence checks.
A PDF lands in an inbox or a Drive folder. Someone opens it, reads the fields, types them into a sheet, files the PDF, and moves on. Do that a few hundred times a month and it's a part-time job. n8n PDF processing removes it: the document gets read, its fields extracted and structured, and the result routed to wherever it belongs, with the original archived.
The pages ranking for this query have a pattern worth noting. The most-cited tutorial recommends shelling out to pdftotext through an Execute Command node and never mentions the built-in PDF node at all. Another tops out at 1,200 words with no confidence check and no batching. None of them show the parse step that turns extracted text into clean fields, which is the exact step that breaks when builders skip it.
Extracting text is easy. Structuring it reliably, and knowing when the extraction is garbage, is the hard part.
What you can automate with PDF processing
n8n reads PDFs with the Extract from File node (which replaced the Read PDF node from version 1.21.0) and structures the output with an AI step. That covers most document jobs:
- Pull fields out of inbound invoices, contracts, or reports and log them to a sheet
- Extract a document's text and push a summary to Slack or Notion
- Read a batch of PDFs from a Drive folder and turn each into a structured row
- Route documents by type after reading their content
- Flag low-confidence extractions to a human review queue
- Archive the original PDF once its data has been captured
The common thread is extract, structure, route. Get those three right and the document type barely matters.
The PDF processing pipeline
Trigger (Gmail / Drive / Webhook upload)
→ Extract from File (PDF → text)
→ Structure (OpenAI → JSON fields)
→ Parse (Code node)
→ Confidence check (IF)
high → route to destination
low → review queue
→ Archive original
The confidence check is what separates a toy from a tool. Extraction quality varies wildly across documents. Without a gate, a misread field flows straight into your system and you trust it until it bites you. With one, the doubtful cases get human eyes and the clean ones flow through untouched.
1. Get the PDF into the workflow
A Gmail trigger catches emailed documents. The Google Drive node pulls them from a watched folder. A Webhook node (n8n-nodes-base.webhook) handles direct uploads. Whatever the source, the PDF arrives as binary data on the item, and that's what the next node reads.
2. Extract the text
Add the Extract from File node and set it to extract from PDF. It reads the binary and returns the document's text at {{$json.text}}. This is the node the most-cited competitor tutorial skips in favor of pdftotext through Execute Command. The built-in node needs no shell access, no system binary, and works the same on n8n Cloud where you can't run arbitrary commands. Use it.
One caveat that trips people up: this reads the text layer. A scanned document that's really just a photo of a page has no text layer, and the node returns empty.
3. Structure the text into fields
Raw text isn't useful; structured fields are. Send the extracted text to the @n8n/n8n-nodes-langchain.openAi v2.1 node with a prompt that asks for the specific fields you need as JSON. The model returns its output at $json.output[0].content[0].text.
For image-only scans, this same step does double duty: an OCR-capable model like GPT-4o-mini Vision reads the page image directly and returns structured fields, covering the case the built-in node can't.
4. Parse before you route
Here's the step tutorials skip and the one that fails silently. The AI returns text. The next node expects an object. Drop a Code node (n8n-nodes-base.code v2, jsCode) that runs JSON.parse on the model output every single time, even when it feels redundant. The execution log makes a missing parse step obvious after the fact; the workflow itself runs green right up until a downstream node reads undefined.
5. Gate on confidence, then route
Have the AI return a confidence score alongside the fields. An IF node (n8n-nodes-base.if v2) sends high-confidence extractions to their destination (a sheet, a database, a CRM) and low-confidence ones to a review tab. The data validation workflow covers the validation rules you layer on top of the confidence gate.
Implementation patterns
Pattern 1 — Inbox PDF to structured row
Gmail trigger (has attachment)
→ Extract from File (PDF → text)
→ OpenAI (extract fields as JSON + confidence)
→ Code (JSON.parse)
→ IF (confidence > 0.8)
high → Google Sheets append
low → Errors tab
The confidence branch is the difference between a sheet you trust and one you re-check by hand. Set the threshold where your documents actually sit, then watch the Errors tab to tune it.
Pattern 2 — Drive folder batch
Schedule Trigger
→ Google Drive (list new PDFs)
→ SplitInBatches (size 10)
→ Extract from File → OpenAI → Code parse
→ Database write
→ next batch
Batching is non-negotiable at volume. PDFs are heavy binary data, and one DEV Community walkthrough processing 30,000+ documents leans entirely on batching to avoid blowing memory. Load ten, extract, write, release, repeat.
Pattern 3 — Route by document type
Extract from File (text)
→ OpenAI (classify: invoice / contract / report)
→ Code (parse)
→ Switch:
invoice → finance sheet
contract → legal Drive folder + Slack alert
report → summary to Notion
Reading the content first, then routing on it, beats routing on filename or sender. Filenames lie; content doesn't. The Switch node fans the structured result out to the right destination per type.
n8n nodes you'll use most
| Node | Purpose |
|---|---|
| Extract from File | Read text from PDF binary data (replaced Read PDF in v1.21.0) |
@n8n/n8n-nodes-langchain.openAi v2.1 | Structure text into JSON fields; OCR scans via Vision |
n8n-nodes-base.code v2 | Parse the AI JSON output before any node consumes it |
n8n-nodes-base.if v2 | Gate on confidence so weak extractions go to review |
n8n-nodes-base.googleDrive | Source PDFs from a folder and archive originals |
n8n-nodes-base.googleSheets | Write structured rows and hold the review queue |
This trips up almost everyone the first time. The Extract from File node reads the PDF's text layer. A document scanned or photographed to PDF often has no text layer, just an image of the page, and the node returns empty with no error. If extraction comes back blank on a file that clearly has words, that's why. Route those through an OCR-capable Vision model instead of the built-in node.
Getting started
- Confirm your n8n is on 1.21.0 or later so the Extract from File node is available.
- Pick a trigger that matches how PDFs arrive: Gmail, Drive, or a webhook upload.
- Add Extract from File and verify
{{$json.text}}actually returns text for your documents. - Add an OpenAI node that returns the fields you need as JSON, plus a confidence score.
- Add a Code node that runs
JSON.parseon the output. Always. - Gate with an IF node and route high vs low confidence separately.
- Batch with SplitInBatches before you point it at a large folder.
For a document pipeline that's already wired end-to-end, the ReceiptLedger shows the extract-structure-route pattern running in production.
Browse the document templates →The ReceiptLedger ships the exact extract-structure-route pipeline this post describes, wired and confidence-gated — it monitors Gmail for attachments, sends each document to GPT-4o-mini Vision for structured field extraction, and a confidence check routes high-quality results to your destination sheet while uncertain ones land in a separate Errors tab for review. It's the working reference for any PDF or document workflow, and it's part of The Complete n8n Templates Bundle, a one-time lifetime license to the whole catalog plus future templates if you run more than one document automation.
PDF processing earns its keep when it knows the difference between a clean read and a garbage one. Use the built-in Extract from File node, parse the AI output every time, and gate on confidence before anything reaches your real data. For adjacent flows, the Google Sheets ETL workflow shows where structured rows go next, and the data validation workflow covers the rules that catch a bad extraction before it spreads. When you'd rather start from a working pipeline, the Data Entry Automation Hub applies the same validate-and-route discipline to form intake.
See all data processing templates →Common questions
How do I extract text from a PDF in n8n?
Can n8n read scanned PDFs that are just images?
How do I turn extracted PDF text into structured fields?
How do I process many PDFs in n8n without running out of memory?
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.
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
More automation guides

n8n Retry Logic: Backoff, Idempotency, and Safe Retries
The API you're calling is going to fail sometimes. Not because you did anything wrong, but because networks blip, rate limits kick in, and third-party services have bad afternoons. Good n8n retry logi…

n8n Error Handling: Catch, Notify, and Never Lose a Run
A workflow that fails silently is worse than no workflow at all, because you trust it right up until the day you discover it stopped running last Tuesday. Solid n8n error handling is the difference be…

n8n Cloud vs Self-Hosted: The Real Cost Breakdown
The n8n Cloud vs self-hosted question has a boring, correct answer that most articles dodge: it depends on whether your time is cheaper than a server. On the invoice, self-hosting wins nearly every ti…