DEV Community

Nova Lumen Labs
Nova Lumen Labs

Posted on

Building a document scanner where OCR never leaves the phone (VisionKit + Vision + PDFKit)

Most free document scanners upload your pages to a server for text recognition. Passports, tax forms and receipts included. There's no technical need for that on a modern phone, so I built LumenScan as an experiment in doing all of it locally. This is how it's put together.

The stack

  • Capture: VNDocumentCameraViewController from VisionKit, the same component Apple Notes uses. You get live edge detection, auto-capture, multi-page flow and a corner editor for free. I first wrote a custom AVFoundation camera, then dropped it as the main path; it now only runs on simulators or devices without Apple's scanner.
  • OCR: the Vision framework's text recognition, on device. I set it up to cover English plus Hindi, Tamil and Telugu, since the first target market was India.
  • PDF: PDFKit builds the output and handles annotation and signing. The recognized text is laid under the page image so the PDF is searchable.
  • History: SwiftData.
  • Purchases: RevenueCat, with prices read from StoreKit so the storefront currency shows correctly instead of being hard-coded.

Analytics without betraying the pitch

If the pitch is that nothing leaves the phone, analytics has to be careful. I send only a fixed list of explicit event names, with no autocapture, no session replay, and never document content. The analytics SDK does nothing at all until a real key is configured.

One bug worth sharing

Cancelling Apple's scanner sheet used to open my fallback camera right behind it, so users saw a second camera after backing out. The fix was to treat cancel as closing the whole scan flow. Obvious in hindsight; I only found it by using the app like a user rather than by reading code.

Business model, honestly

Free scans each day, with Pro for unlimited scans, Word export, password-protected PDFs and signing. There is a 7-day trial. Prices vary by storefront.

Feedback wanted

If you've shipped Vision OCR for non-Latin scripts, I'd like to compare notes on accuracy with low light and skewed pages.

Links (I'm the developer):

Disclosure: I used an AI assistant to help draft and edit this post; the technical details come from the app's source code.

Top comments (0)