Skip to content

Cap-go/capacitor-document-scanner

@capgo/capacitor-document-scanner

Capgo - Instant updates for capacitor

Capacitor plugin to scan document iOS and Android

Documentation

The most complete doc is available here: https://capgo.app/docs/plugins/document-scanner/

Compatibility

Plugin version Capacitor compatibility Maintained
v8.*.* v8.*.*
v7.*.* v7.*.* On demand
v6.*.* v6.*.*
v5.*.* v5.*.*

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.

Install

npm install @capgo/capacitor-document-scanner
npx cap sync

Important Notes

Android Emulator Limitations

The ML Kit Document Scanner does not work on Android emulators. This is a limitation of Google Play Services and ML Kit on emulated devices. When testing your app:

  • ✅ Use a physical Android device for testing document scanning
  • ❌ Android emulators will show an error: "Document scanner is not supported on Android emulators"

This limitation is due to:

  • Google Play Services compatibility issues with emulator environments
  • ML Kit Document Scanner requiring actual hardware camera capabilities
  • Emulators lacking the necessary ML Kit runtime components

For development and testing, always use a real Android device.

Demo

Scanning one note

iOS Android
iOS Demo Android Demo

API

scanDocument(...)

scanDocument(options?: ScanDocumentOptions | undefined) => Promise<ScanDocumentResponse>

Opens the device camera and starts the document scanning experience.

Param Type
options ScanDocumentOptions

Returns: Promise<ScanDocumentResponse>


Interfaces

ScanDocumentResponse

Prop Type Description
scannedImages string[] Scanned images in the requested response format.
status ScanDocumentResponseStatus Indicates whether the scan completed or was cancelled.
Method Signature Description
getPluginVersion () => Promise<{ version: string; }> Get the native Capacitor plugin version

ScanDocumentOptions

Prop Type Description Default
croppedImageQuality number Android only: quality of the cropped image from 0 - 100 (100 is best). 100
letUserAdjustCrop boolean Allow the user to adjust the detected crop before saving. On iOS this forces the native VisionKit preview/editor after each capture using the private VisionKit navigation hooks needed to keep the scanner flow alive. On Android this enables ML Kit's crop adjustment flow. true
reviewCapturedDocument boolean When enabled, shows the current scanned page before continuing so the user can review it and explicitly continue or finish the flow. On iOS this forces the native VisionKit preview/editor between captures. On Android this switches to a one-page-at-a-time flow between ML Kit sessions. The review/editor screen is still shown automatically when the scan limit is reached. false
maxNumDocuments number Maximum number of documents to scan. On iOS: VisionKit caps scans at 24 pages (system limit), and the hacked native flow can still stop earlier when you pass a smaller limit. On Android: customizable limit; defaults to 20 for performance (clamped 1-24). Set to 1 for single-scan mode where the scanner stops after one document. 20 on Android, 24 on iOS
responseType ResponseType Format to return scanned images in (file paths or base64 strings). ResponseType.ImageFilePath
brightness number Brightness adjustment applied to scanned images. Range: -255 to 255 (0 = no change, positive = brighter, negative = darker) Useful for compensating low-light scans. 0
contrast number Contrast adjustment applied to scanned images. Range: 0.0 to 10.0 (1.0 = no change, >1 = more contrast, <1 = less contrast) Helps improve text clarity in poorly lit scans. 1.0
scannerMode ScannerMode Android only: scanner mode that controls ML Kit features and filters. - 'base': Basic scan with crop/rotate, no filters or ML cleaning - 'base_with_filter': Adds grayscale and auto-enhancement filters - 'full': All features including ML-based image cleaning (erases stains, fingers, etc.) ScannerMode.Full

Type Aliases

ResponseType

'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect'

Enums

ScanDocumentResponseStatus

Members Value Description
Success 'success' The scan completed successfully.
Cancel 'cancel' The user cancelled the scan flow.

ResponseType

Members Value Description
Base64 'base64' Return scanned images as base64-encoded strings.
ImageFilePath 'imageFilePath' Return scanned images as file paths on disk.

ScannerMode

Members Value Description
Base 'base' Basic document scanning with crop and rotate features only. No filters or ML-based enhancements.
BaseWithFilter 'base_with_filter' Basic features plus automatic filters (grayscale, auto-enhancement).
Full 'full' Full feature set including ML-based image cleaning. Automatically removes stains, fingers, and other artifacts.

credits

This plugin is a re implementation of the original https://document-scanner.js.org Thanks for the original work, we recoded it with more modern SDK but explodes the same API

About

Capacitor plugin to scan document iOS and Android

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors