@preeternal/react-native-document-scanner-plugin
v0.2.2
Published
Fork of react-native-document-scanner-plugin with New Architecture (TurboModule) support and active maintenance.
Readme
@preeternal/react-native-document-scanner-plugin
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 |
| -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
|
Installation
yarn add @preeternal/react-native-document-scanner-pluginAfter installing the plugin, you need to follow the steps below
iOS
Open
ios/Podfileand setplatform :iosto13or higheriOS requires the following usage description be added and filled out for your app in
Info.plist:
NSCameraUsageDescription(Privacy - Camera Usage Description)
- 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
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 }}
/>
)
}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
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[] | This is an array with either file paths or base64 images for the document scan. |
| 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
