In this categoryAutomation · 38
AutomationIntermediate

How to Extract Structured Data from PDFs with n8n

Read a PDF in n8n, send the text to an LLM with a fixed schema, and write clean JSON rows to Google Sheets or a database.

12 minIntermediate

Copying fields out of PDFs by hand does not scale. This guide builds an n8n workflow that pulls the text from a PDF, hands it to a language model with a fixed schema, and writes the result as structured JSON into Google Sheets or a database. The whole thing is four nodes plus a chat model, and it runs unattended once it is on.

  • An n8n instance (cloud or self-hosted)
  • A source for the PDF, such as a Google Drive folder, an email inbox, or an HTTP URL
  • An OpenAI or Anthropic API key for the chat model
  • A destination: a Google Sheet, Postgres, or any database node

Step 1: Get the PDF into the workflow as binary

The text extraction node needs the actual file data, not a link. Start with a trigger, then add a node that returns the PDF as binary: a Google Drive node with the Download File operation, an HTTP Request node pointed at a file URL, or the Gmail node reading an attachment. Run it once so the PDF arrives on a binary property (n8n names it data by default).

Step 2: Pull the raw text with Extract From File

Add the Extract From File node and set Operation to Extract From PDF. Point Input Binary Field at the property that holds your file (data, unless you renamed it). On run, the node converts the PDF into JSON and puts the document text on an output field named text, which you will feed to the model in the next step.

n8n - workflow canvas
Google Drive (Download) -> Extract From File -> Information Extractor -> Google Sheets
binary: data op: Extract From PDF schema -> JSON Append row
^ OpenAI Chat Model (sub-node)
Four nodes carry the PDF from file to structured row.

Step 3: Extract structured fields with an LLM

Add the Information Extractor node from the Advanced AI section. It needs a chat model attached as a sub-node, so connect an OpenAI Chat Model or Anthropic Chat Model underneath it and add your API credential. In the Text field, map the extracted text with an expression such as {{ $json.text }}. Then choose how you describe the output shape.

Schema Type optionWhat you provideBest for
From Attribute DescriptionsA list of field names plus a short description eachQuick setups, a handful of flat fields
Generate From JSON ExampleOne sample JSON object; n8n infers the schemaWhen you already have an example record
Define using JSON SchemaA full JSON Schema you paste inStrict control, nested objects, arrays
Information Extractor - Generate From JSON Example
{
  "vendor": "Vellum Co",
  "invoice_number": "INV-2041",
  "date": "2026-06-12",
  "total": 1240.00,
  "currency": "USD",
  "line_items": [
    { "description": "Design retainer", "amount": 1240.00 }
  ]
}
Note: every field is treated as required
When you use Generate From JSON Example, n8n marks every property as mandatory and ignores the sample values, using only the names and types. If some fields can be absent, switch to Define using JSON Schema and mark them optional, and add a line to the System Prompt telling the model to return null rather than guess. Also note that n8n does not support $ref references inside JSON Schema.

Step 4: Write the JSON to Sheets or a database

The Information Extractor outputs your fields under an output object, ready to map directly. Add a Google Sheets node with the Append Row operation, or a Postgres / MySQL Insert node, and map each field (for example {{ $json.output.vendor }} and {{ $json.output.total }}) to a column. No separate JSON parse step is needed because the node already returns structured data.

n8n - execution log
Extract From File: 1 item, text length 3.2 KB
Information Extractor: calling OpenAI Chat Model...
output: { vendor: 'Vellum Co', invoice_number: 'INV-2041', total: 1240, currency: 'USD' }
Google Sheets: appended 1 row to 'Invoices'
$

Result: any PDF that lands in your source now becomes a clean, schema-checked row in seconds. Test with a few real documents and compare the values against the originals, then activate the workflow so it runs on every new file.

Related guides

Watch related tutorials

Free weekly email

New guides in your inbox

Fresh step-by-step how-to guides as we publish them. One email a week, no more.

Tags
#n8n pdf extraction#extract structured data from pdf#n8n#information extractor#openai