CookbooksOCR Cookbooks
Extract Tables to CSV
Convert bordered and borderless tables in PDFs and scans into clean CSV files with pandas.
- Enable
bbox=trueto get cell positions for every block - Sort table blocks into rows and columns by coordinates
- Export a validated CSV with pandas
Time to complete: ~15 minutes
Prerequisites
- A
SAGEA_API_KEYexported as an environment variable - A document with tables in PDF, PNG, JPG, TIFF, or WEBP format, max 100MB, ideally 300 DPI
- Python 3.9+ with
requestsandpandasinstalled - Set up document processing
- ARVA OCR model card
Step 1: Request OCR with bounding boxes
Set bbox=true and output_format="json" so each table block includes coordinates.
Response shape:
Complex pages with tables cost $2.50 per 1000 pages. Accuracy is 99.2% on clean 300 DPI scans.
Step 2: Reconstruct rows and columns
Group table blocks by vertical position, then sort by horizontal position.
Step 3: Export to CSV with pandas
Normalize column counts and write a clean CSV file.
Verify
| Error | Cause | Fix |
|---|---|---|
401 Unauthorized | Missing or invalid API key | Export a valid key as SAGEA_API_KEY and retry |
400 unsupported_format | File type not in PDF, PNG, JPG, TIFF, WEBP | Convert the file to PDF or PNG and retry |
413 Payload Too Large | File is over 100MB | Compress or split the file, then retry |
429 rate_limit_exceeded | Too many requests at once | Back off with retries and reduce concurrency |
