Ocr and documents

From taracodlabs/aiden · View interactive version

Ocr and documents is an AI agent skill from the GitHub repository taracodlabs/aiden. Extract text from PDFs, images, scans, Word docs (Python)

How to use this skill

Skill file

OCR and Document Text Extraction

Extract readable text from PDFs, scanned images, and Word documents using Python libraries available in most environments. No cloud API required.

When to Use

How to Use

1. Extract text from a PDF (pymupdf — fastest)

import fitz  # pip install pymupdf

doc  = fitz.open("document.pdf")
text = "\n\n".join(page.get_text() for page in doc)
print(text[:2000])  # preview first 2000 chars
doc.close()

2. Extract text from a PDF (pdf-parse via Node.js)

// requires: npm install pdf-parse (already in DevOS dependencies)
const pdfParse = require('pdf-parse')
const fs       = require('fs')
const data     = await pdfParse(fs.readFileSync('document.pdf'))
console.log(data.text.slice(0, 2000))
console.log(`Pages: ${data.numpages}`)

3. OCR a scanned image (Tesseract)

Requires Tesseract installed: winget install UB-Mannheim.TesseractOCR

import pytesseract          # pip install pytesseract
from PIL import Image       # pip install Pillow

img  = Image.open("scan.png")
text = pytesseract.image_to_string(img, lang="eng")
print(text)

4. OCR with preprocessing for better accuracy

import pytesseract
from PIL import Image, ImageFilter, ImageOps

img = Image.open("scan.jpg")
img = ImageOps.grayscale(img)
img = img.filter(ImageFilter.SHARPEN)
img = img.point(lambda p: 255 if p > 128 else 0)  # binarize
text = pytesseract.image_to_string(img, config="--psm 6")
print(text)

5. Extract text from a Word .docx file

from docx import Document   # pip install python-docx

doc   = Document("report.docx")
paras = [p.text for p in doc.paragraphs if p.text.strip()]
text  = "\n".join(paras)
print(text)

6. Extract a specific page range from a PDF

import fitz

doc    = fitz.open("big_report.pdf")
pages  = range(4, 9)   # pages 5-9 (0-indexed)
text   = "\n\n".join(doc[i].get_text() for i in pages)
print(text)

7. Extract tables from a PDF

import pdfplumber   # pip install pdfplumber

with pdfplumber.open("financial_report.pdf") as pdf:
  for page in pdf.pages:
    for table in page.extract_tables():
      for row in table:
        print("\t".join(str(cell or "") for cell in row))

Examples

"Read the text from this PDF contract"

→ Use step 1 (pymupdf) or step 2 (pdf-parse) depending on whether Python or Node is preferred.

"Extract the table from page 3 of this quarterly report PDF"

→ Use step 7 (pdfplumber) targeting pdf.pages[2] for page 3.

"Read the text from this scanned invoice image"

→ Use step 3 or 4 (Tesseract). For low-quality scans, use step 4 with preprocessing.

Cautions

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.