Learn the best techniques to accurately extract tables from scanned invoices, receipts, financial reports, and image-based PDFs using GPT-4o Vision, IBM Docling, and Unstructured PDF Parser.
Extracting tables from scanned PDF documents is significantly more challenging than extracting plain text from searchable PDFs.
Libraries such as pdfplumber, PyPDF, and Camelot depend on embedded text layers. Unfortunately, scanned PDFs contain only images, making these tools ineffective.
Modern AI-powered document processing solves this problem by combining OCR, layout detection, computer vision, and Large Language Models (LLMs).
| Tool | Reads Images? | Preserves Table Layout? | Recommended? |
|---|---|---|---|
| PyPDF | ❌ | ❌ | No |
| pdfplumber | ❌ | ❌ | No |
| Camelot | ❌ | Limited | Only Digital PDFs |
| Tesseract OCR | ✅ | ❌ | Average |
| GPT-4o Vision | ✅ | ✅ | Excellent |
This is currently the most accurate approach for extracting structured tables from scanned documents.
Instead of running OCR first, each PDF page is converted into an image and sent directly to GPT-4o Vision.
Convert pages into images.
Analyze page visually.
Validate extracted schema.
Use structured data.
import base64
from io import BytesIO
from typing import List
from pydantic import BaseModel, Field
from pdf2image import convert_from_path
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage
class TableRow(BaseModel):
item_description: str
quantity: int
unit_price: float
total_amount: float
class ExtractedTable(BaseModel):
table_name: str
rows: List[TableRow]
images = convert_from_path("scanned_invoice.pdf")
buffer = BytesIO()
images[0].save(buffer, format="JPEG")
img_base64 = base64.b64encode(buffer.getvalue()).decode("utf-8")
llm = ChatOpenAI(model="gpt-4o", temperature=0)
structured_llm = llm.with_structured_output(ExtractedTable)
message = HumanMessage(
content=[
{
"type": "text",
"text": "Extract all table data accurately."
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{img_base64}"
}
}
]
)
result = structured_llm.invoke([message])
IBM Research developed Docling to parse complex business documents while preserving layouts, reading order, tables, and document structure.
pip install docling langchain-docling
from langchain_docling import DoclingLoader
from docling.document_converter import DocumentConverter
loader = DoclingLoader(
file_path="scanned_document.pdf",
converter=DocumentConverter()
)
docs = loader.load()
for doc in docs:
print(doc.page_content)
print("=" * 50)
The Unstructured library combines computer vision, OCR, and layout detection models such as YOLOX and Detectron2 to reconstruct scanned tables into HTML or Markdown.
pip install "unstructured[pdf]" poppler-utils tesseract-ocr
from langchain_community.document_loaders import UnstructuredPDFLoader
loader = UnstructuredPDFLoader(
"scanned_table.pdf",
strategy="hi_res",
infer_table_structure=True,
ocr_languages="eng"
)
docs = loader.load()
for doc in docs:
if "Table" in str(doc.metadata):
print(doc.page_content)
| Tool / Strategy | Cost | Accuracy | Setup Difficulty | Best Use Case |
|---|---|---|---|---|
| GPT-4o Vision + Pydantic | API Usage | 95%+ | Easy | Highest accuracy |
| IBM Docling | Free | 85–90% | Medium | Local processing |
| Unstructured (HI_RES) | Free | 80–90% | Medium | Complex layouts |
Choose this when maximum accuracy is your priority and API usage is acceptable.
Ideal for enterprises requiring local processing without sending documents to cloud services.
Great for large batches of scanned documents with complex layouts and multiple tables.
If you're building a production-grade AI document processing application, GPT-4o Vision with Structured Output offers the highest accuracy for extracting structured tables from scanned PDFs while requiring minimal preprocessing.
For organizations needing an entirely local and open-source solution, IBM Docling is an excellent choice. If your workflow involves large-scale scanned documents with complex layouts, Unstructured PDF Parser provides powerful layout-aware OCR capabilities.