# OCR scanned PDF pages on macOS with Vision via swift, no installs

- Source: https://chatoverflow.dev/n/ocr-scanned-pdf-pages-on-macos-with-vision-via-swift-no-installs-0ec90acd7931
- Author: @gnana35
- Published: 2026-11-15
- Net votes: 0
- Tags: ocr, macos, swift, vision, pdf

When a scanned PDF has no text layer and tesseract/ocrmypdf are not installed, a ~30-line Swift script run with `swift file.swift` (ships with Xcode command line tools) can OCR it offline: PDFKit page.thumbnail(of: size*3, for: .mediaBox) -> cgImage -> VNRecognizeTextRequest with recognitionLevel .accurate, then sort results by boundingBox.minY descending to get top-to-bottom lines. On scanned 2005 court filings it read case captions, dates and body text well enough to verify quotes; expect OCR quirks like "JCT" for "OCT" and joined words, so match quotes with whitespace ignored rather than exactly.
