How to Extract Tables from Scanned PDFs into Markdown in Python
B.L.A.S.T. extracts tables from scanned PDFs by combining deep neural layout detection with its built-in TEDS (Tree Edit Distance-based Similarity) evaluator. It identifies borderless table geometry, aligns cell coordinates, and outputs clean GitHub-Flavored Markdown or DOCX tables. Verified in eval/teds_evaluator.py.
CLI Quickstart
git clone https://github.com/Ibrahim-Salman19/OCR.git && cd OCR
pip install -r requirements.txt
python -m blast_ocr.cli balance_sheet.pdf --formats md
Python implementation: table extraction with layout geometry
from blast_ocr.pipeline import BlastPipeline
from eval.teds_evaluator import TEDSEvaluator
# 1. Initialize pipeline with Markdown output
pipeline = BlastPipeline(config_overrides={"ocr_engine": "rapidocr"})
result = pipeline.process_job(source_path="samples/quarterly_earnings.pdf", formats=["markdown"])
# 2. Inspect extracted Markdown tables
with open(result["generated_files"]["markdown"], "r") as f:
markdown_content = f.read()
print(markdown_content)
# 3. Optional: validate structural similarity against a reference table
score = TEDSEvaluator.evaluate(
gold_html="<table><tr><th>Metric</th><th>Q3</th></tr>...</table>",
hyp_html="<table><tr><th>Metric</th><th>Q3</th></tr>...</table>",
)
print(f"Table TEDS Structural Accuracy: {score:.4f}")
Visual table alignment comparison
| Account Name | FY2025 | FY2026 |
|---|---|---|
| Operating Revenue | $450,200 | $612,400 |
| Research & Dev (SIMD) | $120,500 | $145,000 |
| Net Operating Income | $329,700 | $467,400 |
That's the exact GitHub-Flavored Markdown table B.L.A.S.T. writes to disk -- no post-processing needed to paste it into a README or RAG index.
The TEDS protocol for table evaluation
Plain-text OCR is scored with Character Error Rate (CER); table structure needs a different metric because row/column topology matters as much as the text. Tree Edit Distance-based Similarity (TEDS) treats each table as an HTML DOM tree and scores:
TEDS(Ta, Tb) = 1 - EditDistance(Ta, Tb) / max(|Ta|, |Tb|)
Tree nodes are <table>, <tr>, <td>, <th>, and their text content; edit operations are insertion, deletion, and substitution. A score of 1.000 is a perfect match. The evaluator itself is unit-tested for correctness (tests/test_teds_evaluator.py), but this project has not yet recorded an end-to-end TEDS score on a real table corpus -- per docs/BENCHMARKS_2026.md, treat any specific TEDS percentage for this project as aspirational until that file reports one.