@capgo/capacitor-document-scanner

中文文档
8.4.17发布于 2026/11/02MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 11.2万

Capacitor plugin to scan document iOS and Android

原始使用文档
文档目录16 节
  1. ➡️ Get started for free
  2. Key features
  3. Documentation
  4. Compatibility
  5. Install
  6. Important Notes
  7. Android Emulator Limitations
  8. iOS App Store review and the VisionKit swizzle
  9. Demo
  10. Scanning one note
  11. API
  12. scanDocument(...)
  13. Interfaces
  14. Type Aliases
  15. Enums
  16. credits

@capgo/capacitor-document-scanner

Scan paper documents with the native scanner UI: VisionKit on iOS and Google ML Kit on Android find the page edges, fix the perspective and return clean images. Add receipt, ID or contract capture to your app without building a camera screen.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-document-scanner in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-document-scanner to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

Example app on iOS scanning a handwritten page: the scanner finds the page edges and the scanned image appears in the app

Key features

  • Native scanner UI: scanDocument() opens the VisionKit document camera on iOS and the ML Kit document scanner on Android, with automatic edge detection and perspective correction.
  • Multi-page scans: capture up to 24 pages in one session, or pass maxNumDocuments: 1 for single-page mode. Android stops after that page. On iOS the camera stops only when iosVisionKitSwizzle is enabled; the default binary drops the extra pages after Save.
  • Crop and review: Android always offers crop and rotate. On iOS, VisionKit shows its review screen before Save. Forcing the editor after every capture is an opt-in swizzle. See iOS App Store review.
  • Image cleanup: tune brightness and contrast on both platforms. On Android, scannerMode adds filters and ML cleaning that removes stains and fingers.
  • Flexible output: get file paths or base64 strings with responseType, plus a success or cancel status.
  • Platforms: iOS and Android. Web is not supported: scanDocument() rejects as unimplemented.

Documentation

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

Compatibility

Plugin versionCapacitor compatibilityMaintained
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

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-document-scanner` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

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.

iOS App Store review and the VisionKit swizzle

The default iOS binary does not include the private VisionKit swizzle. Those calls load VNDocumentCameraViewController_InProcess with NSClassFromString and exchange documentCameraController:canAddImages: through method_exchangeImplementations. The same code reads private UIKit gesture state so it can open the crop editor. The iPhoneOS 27.1 SDK still has no public page-limit or per-capture callback on VNDocumentCameraViewController.

This follows @capgo/capacitor-social-login: the swizzle stays out of the build unless the app opts in.

With the default build:

  • Scanning uses the public VNDocumentCameraViewController API.
  • maxNumDocuments trims the pages returned after Save. The camera can still capture up to VisionKit's 24-page system limit.
  • letUserAdjustCrop and reviewCapturedDocument do not force the editor after each capture. VisionKit's own review screen before Save is unchanged.
  • Android behavior is unchanged.

Enable the swizzle when you need that iOS behavior back:

import type { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  plugins: {
    DocumentScanner: {
      iosVisionKitSwizzle: true,
    },
  },
};

export default config;

Then run bunx cap sync. That command writes the flag into Package.swift and CapgoCapacitorDocumentScanner.podspec in the installed plugin, and the next iOS build compiles CAPGO_DOCUMENT_SCANNER_VISIONKIT_SWIZZLE. Remove the flag and run bunx cap sync again to ship the default binary.

With the swizzle compiled in:

  • maxNumDocuments stops the camera when the limit is reached. VisionKit's own cap is still 24.
  • letUserAdjustCrop opens the VisionKit editor after each capture.
  • reviewCapturedDocument shows the current page before the next capture, and the editor still opens when the limit is reached.
  • The binary contains method_exchangeImplementations, the private class lookup, and the private gesture reads. Android is unchanged.

That can make App Store review harder. Static analysis may name method_exchangeImplementations. You can still explain the use in the review notes: the swizzle only caps the page count and opens the editor inside Apple's document scanner. It does not read private user data, and it does not change anything outside that screen. Some submissions get a question and are approved after that explanation. Others go through with no mention of the symbol. Approval is per submission, so a previous pass does not decide the next binary.

Demo

Scanning one note

iOSAndroid
iOS DemoAndroid Demo

API

scanDocument(...)

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

Opens the device camera and starts the document scanning experience.

ParamType
optionsScanDocumentOptions

Returns: Promise<ScanDocumentResponse>


Interfaces

ScanDocumentResponse

PropTypeDescription
scannedImagesstring[]Scanned images in the requested response format.
statusScanDocumentResponseStatusIndicates whether the scan completed or was cancelled.
MethodSignatureDescription
getPluginVersion() => Promise<{ version: string; }>Get the native Capacitor plugin version

ScanDocumentOptions

PropTypeDescriptionDefault
croppedImageQualitynumberAndroid only: quality of the cropped image from 0 - 100 (100 is best).100
letUserAdjustCropbooleanAllow the user to adjust the detected crop before saving. On iOS, VisionKit already shows its own review screen before Save. Forcing that editor after every capture needs the private VisionKit swizzle, which is not compiled into the default binary. Set plugins.DocumentScanner.iosVisionKitSwizzle to true and run bunx cap sync to include it. See the README. On Android, crop/rotate is always part of the ML Kit UI in every ScannerMode; use scannerMode to control filters and ML cleaning instead.true
reviewCapturedDocumentbooleanWhen 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 only when plugins.DocumentScanner.iosVisionKitSwizzle is compiled in. The default binary leaves the system review screen before Save unchanged. On Android this switches to a one-page-at-a-time flow between ML Kit sessions. With the iOS swizzle enabled, the review/editor screen is still shown when the scan limit is reached.false
maxNumDocumentsnumberMaximum number of documents to scan. On iOS the default binary uses public VisionKit and trims the returned pages to this limit after Save. VisionKit itself still allows up to 24 captures. Stopping the camera at a lower limit requires plugins.DocumentScanner.iosVisionKitSwizzle. On Android: customizable limit; defaults to 20 for performance (clamped 1-24). Set to 1 for single-scan mode. Android stops after one document. On iOS the camera stops after one document only when plugins.DocumentScanner.iosVisionKitSwizzle is compiled in.20 on Android, 24 on iOS
responseTypeResponseTypeFormat to return scanned images in (file paths or base64 strings).ResponseType.ImageFilePath
brightnessnumberBrightness adjustment applied to scanned images. Range: -255 to 255 (0 = no change, positive = brighter, negative = darker) Useful for compensating low-light scans.0
contrastnumberContrast 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
scannerModeScannerModeAndroid only: scanner mode that controls ML Kit features and filters. Independent of letUserAdjustCrop (crop/rotate is available in all modes). - '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

MembersValueDescription
Success'success'The scan completed successfully.
Cancel'cancel'The user cancelled the scan flow.

ResponseType

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

ScannerMode

MembersValueDescription
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

版本与发布记录

@capgo/capacitor-document-scanner 共发布 79 个版本,首次发布于 2025/10/09;过去 12 个月发布了 58 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.4.17latest2026/11/026 天前
8.4.162026/10/2613 天前
8.4.152026/10/2415 天前
8.4.142026/10/1920 天前
8.4.132026/10/1525 天前
8.4.122026/10/1327 天前

关于 @capgo/capacitor-document-scanner 的常见问题

@capgo/capacitor-document-scanner 是什么?

Capacitor plugin to scan document iOS and Android

如何安装 @capgo/capacitor-document-scanner?

在项目目录运行 npm install @capgo/capacitor-document-scanner,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-document-scanner 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-document-scanner 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-document-scanner 可以商用吗?

@capgo/capacitor-document-scanner 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-document-scanner 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-document-scanner 在 2026/10/09 – 2026/11/07 这 30 天内被下载 112,231 次,日均约 3,741 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-document-scanner 还在维护吗?

最新版本 8.4.17 发布于 2026/11/02(6 天前);至今共发布 79 个版本,其中过去 12 个月发布了 58 个;首次发布于 2025/10/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。