chandra-ocr
Extract text from complex documents using Chandra OCR — handles tables, forms, handwriting, and full page layouts with high accuracy. Use when: extracting data from scanned documents, reading complex tables from PDFs/images, processing handwritten forms.
What this skill does
# Chandra OCR
Extract text from complex documents — tables, forms, handwriting, and full page layouts — using [Chandra](https://github.com/datalab-to/chandra), a high-accuracy OCR engine built for real-world document complexity.
## Overview
Chandra OCR handles the document types that trip up standard OCR: multi-column tables with merged cells, mixed print and handwriting, and complex page layouts. It outputs structured data (DataFrames, JSON) and supports GPU acceleration for batch processing.
## Instructions
### Installation
```bash
pip install chandra-ocr
```
For GPU acceleration (recommended for batch processing):
```bash
pip install chandra-ocr[gpu]
```
### Basic Text Extraction
```python
from chandra import OCR
ocr = OCR()
result = ocr.read("document.png")
print(result.text)
# From a PDF
result = ocr.read("report.pdf")
for page in result.pages:
print(f"--- Page {page.number} ---")
print(page.text)
```
### Layout-Preserved Extraction
```python
result = ocr.read("document.png", preserve_layout=True)
for block in result.blocks:
print(f"Type: {block.type}") # paragraph, table, header, handwriting
print(f"Text: {block.text}")
print(f"Confidence: {block.confidence:.2f}")
```
### Table Extraction
```python
result = ocr.read("invoice.png", extract_tables=True)
for table in result.tables:
print(f"Table: {table.rows} rows x {table.cols} columns")
df = table.to_dataframe()
print(df.head())
table.to_csv("extracted_table.csv")
```
### Handwriting Recognition
```python
result = ocr.read("handwritten_form.jpg", mode="handwriting")
for block in result.blocks:
if block.type == "handwriting":
print(f"Handwritten: {block.text} (conf: {block.confidence:.2f})")
```
### Mixed Documents (Print + Handwriting)
```python
result = ocr.read("filled_form.png", mode="mixed")
for block in result.blocks:
print(f"[{block.type}] {block.text} (conf: {block.confidence:.2f})")
```
### Batch Processing
```python
import glob
from chandra import OCR
import json
ocr = OCR(device="cuda")
files = glob.glob("documents/*.pdf")
for file_path in files:
result = ocr.read(file_path, extract_tables=True)
output = {
"file": file_path,
"pages": len(result.pages),
"text": result.text,
"tables": [t.to_dict() for t in result.tables],
}
with open(file_path.replace(".pdf", ".json"), "w") as f:
json.dump(output, f, indent=2)
```
## Examples
### Example 1: Extract Invoice Tables to CSV
```python
from chandra import OCR
ocr = OCR()
result = ocr.read("invoice-2025-0342.pdf", extract_tables=True)
for i, table in enumerate(result.tables):
df = table.to_dataframe()
df.to_csv(f"invoice_table_{i}.csv", index=False)
print(f"Table {i}: {table.rows} rows — columns: {list(df.columns)}")
# Output:
# Table 0: 12 rows — columns: ['Item', 'Qty', 'Unit Price', 'Total']
# Table 1: 3 rows — columns: ['Tax Type', 'Rate', 'Amount']
```
### Example 2: Process Handwritten Medical Forms
```python
from chandra import OCR
import requests
ocr = OCR()
result = ocr.read("patient_intake_form.jpg", mode="mixed", extract_tables=True)
extracted = {}
for block in result.blocks:
extracted[block.label] = {
"value": block.text,
"confidence": block.confidence,
"needs_review": block.confidence < 0.85,
}
review_fields = {k: v for k, v in extracted.items() if v["needs_review"]}
print(f"Fields needing review: {list(review_fields.keys())}")
# Output:
# Fields needing review: ['allergies', 'signature']
```
## Guidelines
- Use `device="cuda"` for batch processing — 5-10x faster than CPU
- Set `dpi=300` or higher for scanned documents to improve accuracy
- For forms with checkboxes, use `mode="mixed"` to detect both print and marks
- Confidence threshold of 0.85 is a good default for human review routing
- Pre-process images (deskew, denoise) for better results on poor-quality scans
| Option | Default | Description |
|--------|---------|-------------|
| `mode` | `"auto"` | Detection mode: `auto`, `print`, `handwriting`, `mixed` |
| `preserve_layout` | `False` | Maintain spatial positioning of text |
| `extract_tables` | `False` | Detect and extract tables as structured data |
| `device` | `"cpu"` | Processing device: `cpu` or `cuda` |
| `language` | `"en"` | Primary language hint |
| `dpi` | `300` | DPI for PDF rasterization |
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.