Prompt

How do I extract invoice fields from PDFs automatically?

Technology / Data Infrastructure1 observationLast seen Oct 11, 2026

Latest observation

Oct 11, 2026OpenAI APIWeb search: off

To extract invoice fields from PDFs automatically, you generally use a pipeline with 4 parts:

  1. Get the text from the PDF
  2. Detect which parts are invoice fields
  3. Normalize the values
  4. Export to structured data like JSON, CSV, or a database

1) Identify the PDF type

There are two main cases:

  • Digital PDFs: text is selectable/copyable
    • Use PDF text extraction tools directly
  • Scanned PDFs: page is just an image
    • Use OCR first

2) Common tools

For text-based PDFs

  • Python libraries: pdfplumber, PyMuPDF (fitz), pypdf
  • Good for extracting text, tables, and coordinates

For scanned PDFs

  • OCR tools: Tesseract, EasyOCR, AWS Textract, Google Document AI, Azure Form Recognizer
  • Better when invoices are scanned images or low-quality PDFs

For field extraction

  • Rule-based parsing
    • regex for invoice number, date, totals, tax, etc.
  • Template-based extraction
    • if invoices come from a few known vendors/formats
  • ML/document AI
    • if invoice formats vary a lot

3) Fields you typically extract

Common invoice fields:

  • Invoice number
  • Invoice date
  • Vendor name
  • Vendor address
  • Buyer/customer name
  • PO number
  • Line items
  • Subtotal
  • Tax/VAT
  • Total amount
  • Currency
  • Due date
  • Payment terms

4) Simple approach with Python

Step A: Extract text

import pdfplumber

with pdfplumber.open("invoice.pdf") as pdf:
    text = ""
    for page in pdf.pages:
        text += page.extract_text() or ""
print(text)

Step B: Extract fields with regex

import re

invoice_number = re.search(r"Invoice\s*#?:?\s*([A-Z0-9-]+)", text, re.IGNORECASE)
date_match = re.search(r"Invoice Date:?\s*([0-9]{2}/[0-9]{2}/[0-9]{4})", text, re.IGNORECASE)
total_match = re.search(r"Total:?\s*\$?([0-9,]+\.\d{2})", text, re.IGNORECASE)

data = {
    "invoice_number": invoice_number.group(1) if invoice_number else None,
    "invoice_date": date_match.group(1) if date_match else None,
    "total": total_match.group(1) if total_match else None,
}
print(data)

5) Better approach for varied invoice layouts

If invoices differ a lot, use an invoice extraction service:

  • AWS Textract AnalyzeExpense
  • Google Document AI Invoice Parser
  • Azure Form Recognizer prebuilt invoice model
  • Open-source models: LayoutLM, Donut, invoice-specific OCR pipelines

These services can detect:

  • key-value fields
  • line items
  • tables
  • confidence scores

6) Recommended production workflow

  1. Upload PDF
  2. Detect scanned vs digital
  3. Extract text/OCR
  4. Parse invoice fields
  5. Validate results
    • dates format
    • totals sum correctly
    • currency consistency
  6. Send low-confidence cases to human review
  7. Store output in JSON/database

7) Example output format

{
  "invoice_number": "INV-10293",
  "invoice_date": "2026-01-14",
  "vendor_name": "Acme Supplies Ltd",
  "subtotal": 120.00,
  "tax": 24.00,
  "total": 144.00,
  "currency": "USD"
}

8) Practical recommendation

  • If you have simple, consistent invoices: use pdfplumber + regex
  • If you have scanned invoices: use OCR
  • If you have many vendors/formats: use a document AI service or ML model

If you want, I can also give you:

  1. a Python script that extracts common invoice fields, or
  2. a full OCR + parsing pipeline for scanned PDFs.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.