@dariyd/react-native-document-scanner

中文文档
2.2.0发布于 2026/10/27MITTypeScriptCommonJS零依赖近 30 天下载 4.3万

React Native document scanner using VisionKit (iOS) and ML Kit (Android) with support for both old and new architecture

原始使用文档
文档目录38 节
  1. Preview
  2. Used in Production Apps
  3. Features
  4. Installation
  5. From npm (Recommended)
  6. From GitHub (Latest Development)
  7. iOS Installation
  8. Android Installation
  9. Post-install Steps
  10. iOS
  11. Android
  12. React Native New Architecture
  13. Requirements
  14. Enabling New Architecture
  15. Usage
  16. Methods
  17. launchScanner()
  18. Options
  19. Scanner Modes (Android only)
  20. The Response Object
  21. Image Object
  22. PDF Object (Android only)
  23. EXIF Object
  24. Location Permission Setup
  25. iOS
  26. Android
  27. Permission Behavior
  28. Location Accuracy
  29. iOS: Building Without Location
  30. Platform Differences
  31. iOS
  32. Android
  33. Troubleshooting
  34. Android: ML Kit not available
  35. iOS: Camera permission denied
  36. Example
  37. Inspired By
  38. License

react-native-document-scanner

npm version license

Fast, native React Native document scanner for iOS and Android using Apple VisionKit (iOS) and Google ML Kit (Android). Features automatic document detection, edge/perspective correction, multi‑page scanning, configurable image quality, optional Base64, and support for the React Native New Architecture on ios and android.

  • iOS: Uses VisionKit framework and VNDocumentCameraViewController
  • Android: Uses ML Kit Document Scanner API

Preview

iOS DemoAndroid Demo
iOS document scanner demoAndroid document scanner demo

Used in Production Apps

FileNest AI - Docs OrganizerMyGarage - CarDocs & HistoryMyLabStory
FileNest AIMyGarageMyLabStory

Features

  • 📱 Cross-platform support (iOS 13+ and Android API 21+)
  • 🚀 iOS & Android: Full support for new React Native architecture (Fabric/TurboModules)
  • 📸 Automatic document detection and scanning
  • 🖼️ Multi-page document scanning
  • ⚙️ Configurable image quality
  • 📐 Optional max width/height to cap image size
  • 📄 Android: optional PDF output and configurable ML Kit scanner (page limit, gallery import, scanner mode)
  • 📦 Optional base64 encoding
  • 🎯 Platform parity - same API for both platforms

Keywords: React Native document scanner, VisionKit document scanner, ML Kit document scanner, scan documents React Native, edge detection, perspective correction, multi‑page scanner

Installation

npm install @dariyd/react-native-document-scanner

or with yarn:

yarn add @dariyd/react-native-document-scanner

From GitHub (Latest Development)

npm install https://github.com/dariyd/react-native-document-scanner.git

or

yarn add https://github.com/dariyd/react-native-document-scanner.git

iOS Installation

cd ios && pod install

Android Installation

No additional steps required. The ML Kit dependency will be automatically included.

Post-install Steps

iOS

Add the NSCameraUsageDescription key to your Info.plist:

<key>NSCameraUsageDescription</key>
<string>We need access to your camera to scan documents</string>

Android

Add camera permission to your AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA" />

The module automatically requests camera permission when launching the scanner.

React Native New Architecture

This module requires React Native 0.77.3 or higher and supports the new architecture on iOS, while using the stable old architecture on Android.

iOS: Full support for Fabric and TurboModules - automatically detected and enabled when you enable new architecture in your project.

Android: Uses the stable bridge implementation for maximum compatibility. New architecture support is planned for a future release.

Requirements

  • React Native 0.77.3 or higher
  • React 18.2.0 or higher
  • iOS 13.0 or higher
  • Android:
    • Minimum SDK: API 21 (Android 5.0)
    • Target SDK: API 35 (Android 15) - required by Google Play Store
    • Compile SDK: API 35

Enabling New Architecture

✅ iOS: Fully supported - Set RCT_NEW_ARCH_ENABLED=1 in your Podfile or build settings

✅ Android: Fully supported - Keep newArchEnabled=true in your gradle.properties

The iOS implementation will automatically use Fabric/TurboModules when enabled, while Android will continue to use the stable bridge implementation.

Usage

import { launchScanner } from 'react-native-document-scanner';

// Basic usage
const result = await launchScanner();

// With options
const result = await launchScanner({
  quality: 0.8,
  includeBase64: false,
});

// With EXIF metadata
const result = await launchScanner({
  quality: 0.8,
  includeExif: true,
});
console.log('EXIF:', result.images[0].exif);

// With EXIF + GPS location
const result = await launchScanner({
  quality: 0.8,
  includeExif: true,
  includeLocationExif: true,
});
console.log('GPS:', result.images[0].exif?.GPSLatitude, result.images[0].exif?.GPSLongitude);

// Cap image size (e.g. to keep uploads small)
const result = await launchScanner({
  quality: 0.85,
  maxWidth: 2048,
  maxHeight: 2048,
});

// Android only: configure the ML Kit scanner and get a PDF too
// (these options are ignored on iOS, `result.pdf` is never set there)
const result = await launchScanner({
  pageLimit: 20,
  galleryImportAllowed: true,
  scannerMode: 'base_with_filter',
  includePdf: true,
});
console.log('Images:', result.images);
if (result.pdf) {
  console.log('PDF:', result.pdf.uri, result.pdf.pageCount, 'pages');
}

// With callback (optional)
launchScanner({ quality: 0.9 }, (result) => {
  if (result.didCancel) {
    console.log('User cancelled');
  } else if (result.error) {
    console.log('Error:', result.errorMessage);
  } else {
    console.log('Scanned images:', result.images);
  }
});

API Reference

Methods

import {launchScanner} from 'react-native-document-scanner';

launchScanner()

Launch scanner to scan documents.

See Options for further information on options.

The callback will be called with a response object, refer to The Response Object.

Options

OptioniOSAndroidDescription
quality✅✅Number between 0 and 1 for image quality (default: 1). Lower values reduce file size
includeBase64✅✅If true, creates base64 string of the image (Avoid using on large image files due to performance)
includeExif✅✅If true, embeds EXIF metadata (timestamps, device info, dimensions) in the image file and returns it in the response (default: false)
includeLocationExif✅✅If true, also embeds GPS coordinates in EXIF. Requires location permission — see Location Permission Setup (default: false)
locationAccuracy✅✅Target accuracy of the embedded location: 'approximate' (~3 km), 'balanced' (~100 m) or 'precise' (best). Also sets which permission level is needed — see Location Accuracy (default: 'precise')
requestLocationPermission✅✅If false, the scanner never prompts for location permission; GPS is embedded only when permission is already granted. Use when your app asks for location itself (default: true)
locationPurposeKey✅❌Key in NSLocationTemporaryUsageDescriptionDictionary. When set, a user who granted only approximate location is asked for temporary precise location if locationAccuracy needs it (default: none)
maxWidth✅✅Max width in pixels. If the scanned image is wider, it is scaled down before encoding (aspect ratio preserved). 0 or omitted = no cap (default: 0)
maxHeight✅✅Max height in pixels. Works together with maxWidth — the smaller scale factor wins so neither side exceeds its cap. 0 or omitted = no cap (default: 0)
pageLimit❌✅⚠️ Android only. Max number of pages per scan session. Values below 1 are treated as 1 (default: 10)
galleryImportAllowed❌✅⚠️ Android only. If true, the user can import images from the gallery instead of the camera (default: false)
scannerMode❌✅⚠️ Android only. 'base', 'base_with_filter' or 'full' — see Scanner Modes (default: 'full')
includePdf❌✅⚠️ Android only. If true, the response also contains a pdf object with all pages — see PDF Object. images is always returned (default: false)

⚠️ The four options above configure the ML Kit scanner and are ignored on iOS — passing them is safe, they simply have no effect there.

Scanner Modes (Android only)

ModeDescription
baseBasic editing: crop, rotate, reorder pages
base_with_filterbase + image filters (grayscale, auto enhancement)
fullbase_with_filter + ML-enabled cleaning (erase stains, fingers, etc.). This is the default

The Response Object

keyiOSAndroidDescription
didCancel✅✅true if the user cancelled the process
error✅✅true if error happens
errorMessage✅✅Description of the error, use it for debug purpose only
images✅✅Array of the selected media, refer to Image Object
pdf❌✅⚠️ Android only. PDF of all pages, only if includePdf is true — refer to PDF Object

Image Object

keyiOSAndroidDescription
base64✅✅The base64 string of the image (if includeBase64 is true)
uri✅✅The file uri in app specific cache storage
width✅✅Image width in pixels
height✅✅Image height in pixels
fileSize✅✅The file size in bytes
type✅✅The file MIME type (e.g., "image/jpeg")
fileName✅✅The file name
exif✅✅EXIF metadata object (if includeExif is true). See EXIF Object

PDF Object (Android only)

When includePdf is true on Android, the response also contains a pdf object. It is never present on iOS.

keyiOSAndroidDescription
uri❌✅The file uri in app specific cache storage
pageCount❌✅Number of pages in the PDF
fileSize❌✅The file size in bytes
type❌✅The file MIME type ("application/pdf")
fileName❌✅The file name

⚠️ The PDF is built by ML Kit at its own resolution. The quality, maxWidth / maxHeight and includeExif / includeLocationExif options only apply to the images in images, not to the PDF.

EXIF Object

When includeExif is true, each image includes an exif object with the following fields:

keyiOSAndroidDescription
DateTimeOriginal✅✅Scan timestamp (format: yyyy:MM:dd HH:mm:ss)
DateTimeDigitized✅✅Scan timestamp (format: yyyy:MM:dd HH:mm:ss)
PixelXDimension✅✅Image width in pixels
PixelYDimension✅✅Image height in pixels
ColorSpace✅✅Color space (1 = sRGB)
Make✅✅Device manufacturer
Model✅✅Device model
Software✅✅App name
GPSLatitude✅✅Latitude (only if includeLocationExif is true and permission granted)
GPSLongitude✅✅Longitude (only if includeLocationExif is true and permission granted)
GPSAltitude✅✅Altitude in meters
GPSHorizontalAccuracy✅✅GPS accuracy in meters
GPSDateTimeUTC✅✅GPS fix timestamp in UTC

Location Permission Setup

When using includeLocationExif: true, the package requests location permission when needed (unless requestLocationPermission: false). You must add the required permission keys to your app:

iOS

Add to your Info.plist:

<key>NSLocationWhenInUseUsageDescription</key>
<string>Your location will be embedded in scanned documents for record-keeping.</string>

Android

No additional setup required. The package declares ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions in its own manifest, which will be merged automatically.

Permission Behavior

  • If the permission level needed for locationAccuracy has not been granted yet, the system dialog appears before the camera opens — asking for exactly that level (approximate for 'approximate', precise otherwise)
  • If permission was already granted at that level, no dialog is shown
  • If permission was denied, GPS fields are silently skipped and scanning proceeds normally
  • With requestLocationPermission: false the scanner never shows a dialog — ask for location in your app before scanning if you want GPS
  • Location permission is only requested when includeLocationExif: true — it has no effect otherwise

Location Accuracy

Location is best-effort and never delays the camera. The scanner opens immediately; a recent cached fix (less than 5 minutes old) is used straight away, and location updates run while the user scans, keeping the most accurate fix. Updates stop as soon as a fix reaches the locationAccuracy target, or when the scanner closes. The best fix obtained is embedded when the scan is saved — GPSHorizontalAccuracy and GPSDateTimeUTC tell you how precise it is and when it was taken.

locationAccuracyTargetPermission needediOSAndroid
'approximate'~3 kmapproximatekCLLocationAccuracyThreeKilometersACCESS_COARSE_LOCATION, PRIORITY_LOW_POWER
'balanced'~100 mprecisekCLLocationAccuracyHundredMetersACCESS_FINE_LOCATION, PRIORITY_BALANCED_POWER_ACCURACY
'precise'bestprecisekCLLocationAccuracyBestACCESS_FINE_LOCATION, PRIORITY_HIGH_ACCURACY

If only approximate permission is granted while a precise level is requested, the best approximate fix is embedded. A very fast scan with no cached fix, or no location signal (e.g. airplane mode without a recent fix), simply produces an image without GPS.

iOS: Building Without Location

The location code is built into your app even if you never set includeLocationExif, so App Store Connect may warn about a missing NSLocationWhenInUseUsageDescription (ITMS-90683). If your app never uses includeLocationExif, leave the location code out by adding this line near the top of ios/Podfile, then run pod install:

ENV['RNDS_DISABLE_LOCATION'] = '1'

You can also set it for one run instead: RNDS_DISABLE_LOCATION=1 pod install. With location left out, includeLocationExif is ignored and a warning is logged in development.

Platform Differences

While both platforms provide similar functionality, there are some minor differences:

iOS

  • Uses native VisionKit framework
  • Requires iOS 13.0 or higher
  • Supports PNG format for quality = 1.0, JPEG for quality < 1.0

Android

  • Uses Google ML Kit Document Scanner
  • Minimum SDK: API level 21 (Android 5.0)
  • Target SDK: API level 35 (Android 15) - Google Play Store requirement
  • Always outputs JPEG format (plus an optional PDF when includePdf is true)
  • Scanner behavior is configurable via pageLimit, galleryImportAllowed, scannerMode — no iOS equivalents
  • Requires Google Play Services

Troubleshooting

Android: ML Kit not available

If you encounter issues with ML Kit on Android, ensure that:

  1. Google Play Services is installed on the device/emulator
  2. Your compileSdkVersion is 35 or higher
  3. Your targetSdkVersion is 35 (required by Google Play Store)
  4. Your minSdkVersion is 21 or higher

iOS: Camera permission denied

Ensure you've added the NSCameraUsageDescription key to your Info.plist.

Example

Check the example/ directory for a complete example app demonstrating the scanner.

Inspired By

License

MIT

版本与发布记录

@dariyd/react-native-document-scanner 共发布 10 个版本,首次发布于 2025/10/21;过去 12 个月发布了 5 个版本。

版本发布日期距今
2.2.0latest2026/10/2715 天前
2.1.12026/09/141 个月前
2.1.02026/09/141 个月前
2.0.192026/04/027 个月前
2.0.182026/03/177 个月前
2.0.172025/11/111 年前

关于 @dariyd/react-native-document-scanner 的常见问题

@dariyd/react-native-document-scanner 是什么?

React Native document scanner using VisionKit (iOS) and ML Kit (Android) with support for both old and new architecture

如何安装 @dariyd/react-native-document-scanner?

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

@dariyd/react-native-document-scanner 支持 TypeScript 吗?

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

@dariyd/react-native-document-scanner 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dariyd/react-native-document-scanner 可以商用吗?

@dariyd/react-native-document-scanner 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dariyd/react-native-document-scanner 的下载量有多少?

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

@dariyd/react-native-document-scanner 还在维护吗?

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