Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ocr-file

OCR images and scanned PDFs from the command line using Apple's Vision framework. Prints recognized text to stdout — pipe-friendly, zero dependencies beyond macOS.

Built for triaging the pile of memes, screenshots, and scanned PDFs you accumulate and need to search, summarize, or route somewhere else. Inspired by macOCR (which captures screen regions to the clipboard) — ocr-file is the file-in, stdout-out counterpart that composes into shell pipelines.

Install

Requires macOS 11+ and Xcode Command Line Tools (xcode-select --install).

git clone https://github.com/2b3pro/ocr-file.git
cd ocr-file
swiftc -O ocr-file.swift -o ocr-file
sudo mv ocr-file /usr/local/bin/

Usage

ocr-file image.png                            # image → text on stdout
ocr-file scan.pdf                             # all pages, separated by form-feed (\f)
ocr-file scan.pdf --page 3                    # one page
ocr-file scan.pdf --page 2-5 --dpi 300        # range, higher render DPI
ocr-file photo.heic --lang en-US --lang ja-JP # multi-language
ocr-file meme.jpg --fast                      # fast mode

Supports any format NSImage reads (PNG, JPEG, HEIC, TIFF, GIF, BMP) plus PDF (scanned or otherwise — pages are rasterized then OCR'd).

Options

Flag Description
--lang <code> Recognition language (repeatable, e.g. en-US, ja-JP, zh-Hans)
--fast Fast recognition level instead of accurate (no language correction)
--page N or N-M PDF only: OCR a single page (1-indexed) or range
--dpi N PDF only: render DPI (default 200; higher = better OCR, slower)
-h, --help Show help

Pipelines

ocr-file receipt.png | pbcopy                         # to clipboard
ocr-file meme.jpg | apfel "what's this about?"        # triage with on-device LLM
ocr-file scan.pdf | apfel "summarize in 3 bullets"    # digest a scanned doc
ocr-file page.png | grep -i "invoice"                 # filter
for f in *.{png,pdf}; do ocr-file "$f" > "${f%.*}.txt"; done

Exit codes

  • 0 success
  • 1 runtime failure (file not found, decode error, Vision error)
  • 2 usage error

License

MIT

About

OCR an image file from the CLI using Apple's Vision framework. Pipe-friendly.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages