Typical situation: a client sends 500 pages of scanned reports — tables, charts, chaotic text. Regular OCR returns a blob of symbols: columns mixed, rows broken, structure lost. The task of table recognition is to locate tables and restore their grid. We solve this with a pipeline based on Table Transformer, camelot, and post-processing. The result is clean DataFrames ready for loading into a database or Excel.
Table detection is the first step in our pipeline. We are a team with 10+ years of experience in Computer Vision and NLP. We have delivered 40+ projects on table extraction from PDF and images for banks, logistics, and retail. We guarantee >95% accuracy on standard documents and full support after deployment. Our automated table pipeline processes over 1 million pages annually, saving clients an average of $30,000 per year.
How Table Transformer tackles table recognition
State-of-the-art: Table Transformer[1] from Microsoft, based on DETR, trained on PubTables-1M (947k tables from scientific publications). The detector finds tables, the structural recogniser restores rows and columns. For each bounding box we run OCR (Tesseract or EasyOCR) to extract cell text. Comparison: Table Transformer outperforms camelot on scans by 2–3 times in accuracy (93% vs 70%), but requires a GPU.
from transformers import TableTransformerForObjectDetection, DetrImageProcessor
from PIL import Image
import torch
class TableExtractor:
def __init__(self):
# Table detector
self.det_processor = DetrImageProcessor.from_pretrained(
'microsoft/table-transformer-detection'
)
self.det_model = TableTransformerForObjectDetection.from_pretrained(
'microsoft/table-transformer-detection'
)
# Structure recogniser
self.str_processor = DetrImageProcessor.from_pretrained(
'microsoft/table-transformer-structure-recognition'
)
self.str_model = TableTransformerForObjectDetection.from_pretrained(
'microsoft/table-transformer-structure-recognition'
)
def extract_tables(self, image_path: str) -> list[dict]:
image = Image.open(image_path).convert('RGB')
# 1. Detect tables
table_boxes = self._detect_tables(image)
tables = []
for box in table_boxes:
# 2. Crop each table
table_crop = image.crop(box)
# 3. Recognise structure (rows/columns)
structure = self._recognize_structure(table_crop)
# 4. Extract cell text via OCR
cells = self._extract_cell_texts(table_crop, structure)
tables.append({
'bbox': box,
'structure': structure,
'cells': cells,
'dataframe': self._cells_to_dataframe(cells)
})
return tables
def _detect_tables(self, image: Image.Image) -> list[tuple]:
inputs = self.det_processor(images=image, return_tensors='pt')
with torch.no_grad():
outputs = self.det_model(**inputs)
target_sizes = torch.tensor([image.size[::-1]])
results = self.det_processor.post_process_object_detection(
outputs, threshold=0.7, target_sizes=target_sizes
)[0]
boxes = []
for label, box in zip(results['labels'], results['boxes']):
if label == 0: # table class
x1, y1, x2, y2 = box.tolist()
boxes.append((int(x1), int(y1), int(x2), int(y2)))
return boxes
camelot or pdfplumber: which to choose for your task?
For digital PDFs (not scans), camelot is the best choice. Lattice mode works with tables that have lines, stream with aligned text. pdfplumber offers flexibility for mixed documents but requires manual tuning. We select the tool based on document type: for reports with lines — camelot lattice, for complex layouts — pdfplumber with custom settings. The camelot Python library is our go-to for simple table extraction. For digital PDFs, pdfplumber tables extraction works well.
import camelot
def extract_tables_from_pdf(pdf_path: str,
pages: str = 'all') -> list:
# Lattice: for tables with explicit lines
tables_lattice = camelot.read_pdf(
pdf_path, pages=pages, flavor='lattice'
)
# Stream: for tables without lines (aligned text)
tables_stream = camelot.read_pdf(
pdf_path, pages=pages, flavor='stream',
edge_tol=50
)
results = []
for table in tables_lattice:
if table.accuracy > 80:
results.append({
'page': table.page,
'accuracy': table.accuracy,
'dataframe': table.df,
'csv': table.df.to_csv(index=False)
})
return results
pdfplumber for mixed documents
import pdfplumber
import pandas as pd
def extract_tables_pdfplumber(pdf_path: str) -> list[pd.DataFrame]:
tables = []
with pdfplumber.open(pdf_path) as pdf:
for page in pdf.pages:
page_tables = page.extract_tables(
table_settings={
'vertical_strategy': 'lines',
'horizontal_strategy': 'lines',
'snap_tolerance': 3
}
)
for raw_table in page_tables:
# First row as header
df = pd.DataFrame(raw_table[1:], columns=raw_table[0])
tables.append(df)
return tables
Post-processing: table data cleaning
After extraction, cleaning is often needed:
def clean_table(df: pd.DataFrame) -> pd.DataFrame:
# Remove empty rows and columns
df = df.dropna(how='all').dropna(axis=1, how='all')
# Merge multi-line headers
df.columns = [' '.join(str(c).split()) for c in df.columns]
# Numeric columns
for col in df.columns:
try:
df[col] = pd.to_numeric(
df[col].str.replace(',', '.').str.replace(' ', ''),
errors='ignore'
)
except AttributeError:
pass
return df
| Approach | Application | Quality |
|---|---|---|
| Table Transformer | Scans, images | Good |
| camelot (lattice) | PDF with lines | Excellent |
| camelot (stream) | PDF without lines | Fair |
| pdfplumber | Mixed PDF | Good |
| AWS Textract | Cloud, scale | Good |
Project workflow
- Document analysis: study the source document structure, table types, metadata.
- Tool selection: choose the optimal combination (Table Transformer, camelot, pdfplumber) for your case.
- Pipeline development: write detection, recognition, and post-processing scripts.
- Testing: run on 100+ pages, check accuracy, fine-tune model if needed.
- Integration: configure export to CSV, Excel, database, or REST API.
- Documentation and training: hand over code, description, train your team.
What's included (deliverables)
- Source data audit: analysis of table types, complexity assessment.
- Pipeline development: model inference + post-processing.
- Integration: API / DB upload / integration with 1C or Bitrix24.
- Testing and verification: accuracy report on your sample.
- Documentation: architecture description and operation manual.
- Training: 2-3 hour online session for your engineers.
- Support: 1 month after project delivery.
Timelines and cost
| Task | Timeline | Approximate cost |
|---|---|---|
| Extraction from PDF (camelot/pdfplumber) | 1 week | $1,500–$3,000 |
| Scans + Table Transformer | 2–3 weeks | $3,000–$7,000 |
| Complex tables, post-processing | 3–5 weeks | $5,000–$12,000 |
Cost is calculated individually — depends on document volume, complexity, and need for fine-tuning. We estimate your project for free within 1 business day. To get started, just a few sample documents are enough. Typical savings from automated table parsing is 80% on manual data entry costs. Companies typically save $20,000–$100,000 annually after implementation. For a logistics client, we extracted tables from 10,000 PDF invoices daily, reducing manual effort by 90%.
OCR for table cells: Tesseract vs EasyOCR vs cloud APIs
After the table structure is recognised, text from each cell must be extracted. The choice of OCR engine critically affects final accuracy.
Tesseract is a mature open-source engine. It works well with printed text on white background. Requires pre-processing: noise removal, Otsu binarization. Supports 100+ languages via language packs. Speed: ~0.1 sec per cell on CPU.
EasyOCR is a modern neural network alternative. It handles complex fonts and scanning artifacts better. On GPU it is 3–4 times faster than Tesseract with comparable quality. Supports Russian without additional setup.
AWS Textract / Google Vision API are cloud solutions. Best accuracy on complex documents (85–97%), automatic table structure recognition. Suitable for batch processing without GPU. Cost depends on page volume.
Our approach: for scans with good resolution (300+ DPI) we use EasyOCR, for complex multilingual documents — AWS Textract, for on-premise without internet — Tesseract with preprocessing.
Our table parsing pipeline handles complex layouts. Our table automation solution integrates with your workflow. Document data extraction is the core of our service.
Ready to take on your task — we will discuss details and timelines. Get a consultation on choosing the optimal solution.
- Microsoft Table Transformer on Hugging Face







