Skip to content

Preeternal/react-native-document-scanner-plugin

 
 

@preeternal/react-native-document-scanner-plugin

npm version npm downloads

Heads‑up: Upstream now supports New Architecture

The original project, WebsiteBeaver/react-native-document-scanner-plugin, now ships New Architecture (TurboModule) support as well.
This fork remains actively maintained and API‑compatible. If you prefer the upstream package, you can safely use it; if you already rely on this fork, you can continue without changes.

Fork of react-native-document-scanner-plugin with New Architecture (TurboModule) support and active maintenance.

Which package should I use?

  • Use the upstream package (react-native-document-scanner-plugin) if you want to stay on the original repository now that it also supports New Architecture.
  • Use this fork (@preeternal/react-native-document-scanner-plugin) if you want quicker iteration on fixes, Expo/EAS build hardening, and a maintained release cadence. The public API is identical.

Attribution: This package is a community‑maintained fork of the original project by WebsiteBeaver. Demo videos embedded below are from the original repository and are credited to their respective owners.

This is a React Native plugin that lets you scan documents using Android and iOS. You can use it to create apps that let users scan notes, homework, business cards, receipts, or anything with a rectangular shape.

iOS Android
Dollar-iOS Dollar Android

Installation

yarn add @preeternal/react-native-document-scanner-plugin

After installing the plugin, you need to follow the steps below

iOS

  1. Open ios/Podfile and set platform :ios to 13 or higher

  2. iOS requires the following usage description be added and filled out for your app in Info.plist:

  • NSCameraUsageDescription (Privacy - Camera Usage Description)
  1. Install pods by running
cd ios && bundle exec pod install && cd ..

Android

Note: You don't need to prompt the user to accept camera permissions for this plugin to work unless you're using another plugin that requires the user to accept camera permissions. See Android Camera Permissions.

Examples

Demo media in this README is courtesy of the original project (WebsiteBeaver).

Basic Example

import React, { useState, useEffect } from 'react'
import { Image } from 'react-native'
import DocumentScanner from '@preeternal/react-native-document-scanner-plugin'

export default () => {
  const [scannedImage, setScannedImage] = useState();

  const scanDocument = async () => {
    // start the document scanner
    const { scannedImages } = await DocumentScanner.scanDocument()
  
    // get back an array with scanned image file paths
    if (scannedImages.length > 0) {
      // set the img src, so we can view the first scanned image
      setScannedImage(scannedImages[0])
    }
  }

  useEffect(() => {
    // call scanDocument on load
    scanDocument()
  }, []);

  return (
    <Image
      resizeMode="contain"
      style={{ width: '100%', height: '100%' }}
      source={{ uri: scannedImage }}
    />
  )
}

Here's what this example looks like with several items

Dollar.iOS.mp4

Dollar.Android.mp4

Business.Card.iOS.mp4

Business.Card.Android.mp4

Sign.iOS.mp4

Sign.Android.mp4

Notes.iOS.mp4

Notes.Android.mp4

Laptop.iOS.mp4

Laptop.Android.mp4

Limit Number of Scans

You can limit the number of scans. For example if your app lets a user scan a business card you might want them to only capture the front and back. In this case you can set maxNumDocuments to 2. This only works on Android.

import React, { useState, useEffect } from 'react'
import { Image } from 'react-native'
import DocumentScanner from '@preeternal/react-native-document-scanner-plugin'

export default () => {
  const [scannedImage, setScannedImage] = useState();

  const scanDocument = async () => {
    // start the document scanner
    const { scannedImages } = await DocumentScanner.scanDocument({
      maxNumDocuments: 2
    })
  
    // get back an array with scanned image file paths
    if (scannedImages.length > 0) {
      // set the img src, so we can view the first scanned image
      setScannedImage(scannedImages[0])
    }
  }

  useEffect(() => {
    // call scanDocument on load
    scanDocument()
  }, []);

  return (
    <Image
      resizeMode="contain"
      style={{ width: '100%', height: '100%' }}
      source={{ uri: scannedImage }}
    />
  )
}

Limit.Num.Scans.Android.mp4

Differences from the original

  • New Architecture (TurboModule) support — now also available upstream; this fork shipped it earlier and keeps parity.
  • Additional hardening for Expo/EAS and CI examples.
  • Minor documentation updates and ongoing maintenance.

Documentation

Response sanitization (since v0.2.2)

The module now sanitizes results on both platforms, so you no longer need to post‑filter scannedImages in JS:

  • Android: for responseType: 'base64' only non‑empty base64 strings are returned; for URI responses the module verifies the URI is readable via ContentResolver and drops unreachable items.
  • iOS: trims strings, normalizes file:// URLs to filesystem paths and checks file existence before returning.

As a result scannedImages contains only valid items. Example:

const { status, scannedImages } = await DocumentScanner.scanDocument({ responseType: 'imageFilePath' })
if (status === 'success' && scannedImages.length) {
  // All items are valid URIs or base64 strings depending on responseType
  setImage(scannedImages[0])
}

scanDocument(...)

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

Opens the camera, and starts the document scan

Param Type
options ScanDocumentOptions

Returns: Promise<ScanDocumentResponse>


Interfaces

ScanDocumentResponse

Prop Type Description
scannedImages string[] Array of valid file URIs or base64 strings (already sanitized by the module).
status ScanDocumentResponseStatus The status lets you know if the document scan completes successfully, or if the user cancels before completing the document scan.

ScanDocumentOptions

Prop Type Description Default
croppedImageQuality number The quality of the cropped image from 0 - 100. 100 is the best quality. : 100
maxNumDocuments number Android only: The maximum number of photos an user can take (not counting photo retakes) : undefined
responseType ResponseType The response comes back in this format on success. It can be the document scan image file paths or base64 images. : ResponseType.ImageFilePath

Enums

ScanDocumentResponseStatus

Members Value Description
Success 'success' The status comes back as success if the document scan completes successfully.
Cancel 'cancel' The status comes back as cancel if the user closes out of the camera before completing the document scan.

ResponseType

Members Value Description
Base64 'base64' Use this response type if you want document scan returned as base64 images.
ImageFilePath 'imageFilePath' Use this response type if you want document scan returned as inmage file paths.

Common Mistakes

Android Camera Permissions

You don't need to request camera permissions unless you're using another camera plugin that adds <uses-permission android:name="android.permission.CAMERA" /> to the application's AndroidManifest.xml.

In that case if you don't request camera permissions you get this error Error: error - error opening camera: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE

Here's an example of how to request camera permissions.

import React, { useState, useEffect } from 'react'
import { Platform, PermissionsAndroid, Image, Alert } from 'react-native'
import DocumentScanner from '@preeternal/react-native-document-scanner-plugin'

export default () => {
  const [scannedImage, setScannedImage] = useState();

  const scanDocument = async () => {
    // prompt user to accept camera permission request if they haven't already
    if (Platform.OS === 'android' && await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.CAMERA
    ) !== PermissionsAndroid.RESULTS.GRANTED) {
      Alert.alert('Error', 'User must grant camera permissions to use document scanner.')
      return
    }

    // start the document scanner
    const { scannedImages } = await DocumentScanner.scanDocument()
  
    // get back an array with scanned image file paths
    if (scannedImages.length > 0) {
      // set the img src, so we can view the first scanned image
      setScannedImage(scannedImages[0])
    }
  }

  useEffect(() => {
    // call scanDocument on load
    scanDocument()
  }, []);

  return (
    <Image
      resizeMode="contain"
      style={{ width: '100%', height: '100%' }}
      source={{ uri: scannedImage }}
    />
  )
}

Migrating between upstream and this fork

Both packages expose the same public API. To switch:

  • From this fork to upstream

    yarn remove @preeternal/react-native-document-scanner-plugin
    yarn add react-native-document-scanner-plugin
    cd ios && pod install && cd -
  • From upstream to this fork

    yarn remove react-native-document-scanner-plugin
    yarn add @preeternal/react-native-document-scanner-plugin
    cd ios && pod install && cd -

Contributing

Credits

This project builds on the excellent work by WebsiteBeaver/react-native-document-scanner-plugin. The original repository is MIT‑licensed; original copyright notices are preserved in this fork’s LICENSE.

License

MIT

About

Fork of react-native-document-scanner-plugin with New Architecture support and active maintenance

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 39.6%
  • Kotlin 30.0%
  • TypeScript 9.5%
  • JavaScript 7.8%
  • Ruby 6.6%
  • Objective-C++ 5.8%
  • Objective-C 0.7%