Design & media

pdf-extraction

Try it

Extract text, tables, and metadata from PDFs. Auto-detects native text vs scanned image pages and routes to pdfplumber or Tesseract OCR.

What it does

Extract text, tables, and metadata from PDFs. Auto-detects native text vs scanned image pages and routes to pdfplumber or Tesseract OCR.

The skill document

PDF Extraction (auto text / OCR)

Extract content from PDFs without deciding whether each page is selectable text or a scan.

Page typeTool
Native textpdfplumber (text + tables)
Scanned / imagePyMuPDF + Tesseract OCR

Install

# System OCR engine (required for scanned pages)
# Ubuntu/Debian:
sudo apt install tesseract-ocr tesseract-ocr-eng
# Optional Traditional Chinese:
# sudo apt install tesseract-ocr-chi-tra

# CLI — from GitHub (recommended)
pip install "git+https://github.com/alex-ht/pdf-extraction.git@v1.0.0"

# Or install from this skill folder after ClawHub install:
# pip install -e .

Source: https://github.com/alex-ht/pdf-extraction

Quick start

# Auto-detect text vs OCR per page → print text
pdf-extract document.pdf

# Write to file
pdf-extract document.pdf -o out.txt

# See which mode each page will use
pdf-extract document.pdf --analyze-only

# Tables + Markdown
pdf-extract document.pdf --tables --format markdown -o out.md

# JSON (includes per-page mode)
pdf-extract document.pdf --format json -o out.json

# Force mode
pdf-extract scan.pdf --mode ocr --ocr-lang eng
pdf-extract text.pdf --mode text

# Page range
pdf-extract doc.pdf --pages 1-3,5

# Also: python -m pdf_extract document.pdf

Auto mode rules

For each page (--mode auto, default):

  1. Try native text via pdfplumber; count chars and embedded images
  2. Enough text → text
  3. Sparse text (default < 40 non-whitespace chars) or image-heavy → ocr

Tune with --min-text-chars. Override with --mode text or --mode ocr.

Agent usage

When the user provides a PDF and wants content extracted:

  1. Prefer pdf-extract (auto mode). Do not ask whether it is text or scanned.
  2. Use --analyze-only if you only need routing diagnostics.
  3. Use --tables when tables matter (works best on native-text pages).
  4. For Chinese scans, set --ocr-lang eng+chi_tra if chi_tra is installed.
  5. Surface stderr summary lines (which pages used text vs ocr) when useful.

CLI reference

FlagMeaning
-o, --outputWrite to file (default stdout)
-f, --formattext | json | markdown
--modeauto | text | ocr
--pagese.g. 1-3,5
--tablesExtract tables on text pages
--layoutPreserve native text layout
--metaInclude PDF metadata
--ocr-langTesseract langs (default eng)
--ocr-dpiOCR render DPI (default 200)
--analyze-onlyClassification JSON only
-q, --quietSuppress progress on stderr

Dependencies

  • Python 3.10+: pdfplumber, pymupdf, Pillow (see pyproject.toml)
  • System: tesseract (and language packs as needed)

Related skills

Extract text, metadata, and pages from PDF files using pypdf. Use for tasks such as reading PDF content, extracting specific pages, splitting or merging PDFs...

27 installs

Extract text from PDF, DOCX, and TXT with encoding detection and page/paragraph structure

1 installs

Run 50+ PDF and document processing operations through the ComPDF Cloud API from one agent skill.

38 installs99 stars

Render PDF pages to images, extract embedded images, annotate PDFs, and perform advanced PDF inspection using pymupdf (fitz). Use for tasks such as exporting...

29 installs

Recognize text from scanned PDFs and images.