Aulafy
Courses/Advanced and secure RAG/OCR and Tables in Real-World PDFs

OCR and Tables in Real-World PDFs

Easy PDFs already have selectable text. Real enterprise PDFs include scans, columns, stamps, split tables, and skewed invoices. If you don't process that layer properly, your RAG starts out confused.

  • Decide when you need OCR and when plain text extraction is enough.
  • Preserve tables, pages, and metadata before indexing.
  • Create a reviewable intermediate output before embeddings.

Recommended pipeline

TerminalCode
PDF o imagen
  -> detectar si hay texto seleccionable
  -> OCR si hace falta
  -> reconstruir orden de lectura
  -> extraer tablas como HTML/Markdown/JSON
  -> añadir metadatos: documento, página, sección
  -> revisión de muestra
  -> chunking e indexación

Example with Docling

Docling is designed to convert complex documents into structure useful for AI: text, tables, layout, and exportable formats.

TerminalCode
pip install docling

docling factura.pdf --to md --output salida_docling/

# Revisa antes de indexar:
ls salida_docling
cat salida_docling/factura.md

Output format for invoices

TerminalCode
{
  "document_id": "factura-2026-001",
  "page": 1,
  "type": "invoice",
  "supplier": "Proveedor S.L.",
  "invoice_number": "F-2026-001",
  "date": "2026-07-02",
  "total": 242.00,
  "currency": "EUR",
  "table_rows": [
    {"concept": "Servicio mensual", "base": 200.00, "vat": 42.00}
  ],
  "source_text": "fragmento verificable..."
}