55Live document detection library. Returns either a URI or a base64 encoded string of the captured image, allowing you to easily store it or use it as you wish !
66
77Features :
8- - Live detection
9- - Perspective correction and crop of the image
10- - Live camera filters (brightness, saturation, contrast)
11- - Flash
12- - Easy to use base64 image
138
14- #### Can be easily plugged with [ react-native-perspective-image-cropper] ( https://github.com/Michaelvilleneuve/react-native-perspective-image-cropper )
9+ - Live detection
10+ - Perspective correction and crop of the image
11+ - Live camera filters (brightness, saturation, contrast)
12+ - Flash
13+ - Easy to use base64 image
1514
15+ #### Can be easily plugged with [ react-native-perspective-image-cropper] ( https://github.com/Michaelvilleneuve/react-native-perspective-image-cropper )
1616
17- ![ Demo crop gif] ( https://camo.githubusercontent.com/0ac887deaa7263172a5fd2759dba3d692e98585a/68747470733a2f2f73332d65752d776573742d312e616d617a6f6e6177732e636f6d2f6d69636861656c76696c6c656e657576652f64656d6f2d63726f702e676966 )
17+ ![ Demo crop gif] ( https://camo.githubusercontent.com/0ac887deaa7263172a5fd2759dba3d692e98585a/68747470733a2f2f73332d65752d776573742d312e616d617a6f6e6177732e636f6d2f6d69636861656c76696c6c656e657576652f64656d6f2d63726f702e676966 )
1818
19- ## Getting started
19+ ## Both Platform
2020
2121Use version >=1.4.1 if you are using react-native 0.48+
2222
@@ -28,21 +28,57 @@ Edit the `info.plist` file in XCode and add the following permission : `NSCamera
2828
2929Remember, this library uses your device camera, you can't run it on a simulator.
3030
31- ### With Cocoapods
31+ ### iOS if you want to use Cocoapods instead of default linking
3232
3333If you want to use Cocoapods insteads of ` react-native link ` , add the following to your Podfile
3434
3535```
3636 pod 'RNPdfScanner', :path => '../node_modules/react-native-document-scanner/ios'
3737```
3838
39+ ### Android
40+
41+ #### IMPORTANT - Go to folder app/settings.gradle and add
42+
43+ ``` java
44+ include ' :react-native-document-scanner'
45+ project(' :react-native-document-scanner' ). projectDir = new File (rootProject. projectDir, ' ../node_modules/react-native-document-scanner/android' )
46+ ```
47+
48+ #### Link Open CV Library
49+
50+ ``` java
51+ include ' :openCVLibrary310'
52+ project(' :openCVLibrary310' ). projectDir = new File (rootProject. projectDir,' ../node_modules/react-native-document-scanner/android/openCVLibrary310' )
53+ ```
54+
55+ #### In android/app/src/main/AndroidManifest.xml
56+
57+ Change manifest header to avoid "Manifest merger error". After you add ` xmlns:tools="http://schemas.android.com/tools" ` should look like this:
58+
59+ ```
60+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.<yourAppName>" xmlns:tools="http://schemas.android.com/tools">
61+ ```
62+
63+ Add ` tools:replace="android:allowBackup" ` in <application tag. It should look like this:
64+
65+ ```
66+ <application tools:replace="android:allowBackup" android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:allowBackup="false" android:theme="@style/AppTheme">
67+ ```
68+
69+ Add Camera permissions request:
70+
71+ ```
72+ <uses-permission android:name="android.permission.CAMERA" />
73+ ```
3974
4075## Usage
76+
4177``` javascript
42- import React ,{ Component } from ' react' ;
43- import { View , Image } from ' react-native' ;
78+ import React , { Component } from " react" ;
79+ import { View , Image } from " react-native" ;
4480
45- import DocumentScanner from ' react-native-document-scanner' ;
81+ import DocumentScanner from " react-native-document-scanner" ;
4682
4783class YourComponent extends Component {
4884 render () {
@@ -51,61 +87,70 @@ class YourComponent extends Component {
5187 < DocumentScanner
5288 useBase64
5389 saveInAppDocument= {false }
54- onPictureTaken= {data => this .setState ({
55- image: data .croppedImage ,
56- initialImage: data .initialImage ,
57- rectangleCoordinates: data .rectangleCoordinates ,
58- })}
90+ onPictureTaken= {data =>
91+ this .setState ({
92+ image: data .croppedImage ,
93+ initialImage: data .initialImage ,
94+ rectangleCoordinates: data .rectangleCoordinates
95+ })
96+ }
5997 overlayColor= " rgba(255,130,0, 0.7)"
6098 enableTorch= {false }
6199 brightness= {0.3 }
62100 saturation= {1 }
63101 contrast= {1.1 }
64102 quality= {0.5 }
65- onRectangleDetect= {({ stableCounter, lastDetectionType }) => this .setState ({ stableCounter, lastDetectionType })}
103+ onRectangleDetect= {({ stableCounter, lastDetectionType }) =>
104+ this .setState ({ stableCounter, lastDetectionType })
105+ }
66106 detectionCountBeforeCapture= {5 }
67107 detectionRefreshRateInMS= {50 }
68108 / >
69- < Image source= {{ uri: ` data:image/jpeg;base64,${ this .state .image } ` }} resizeMode= " contain" / >
109+ < Image
110+ source= {{ uri: ` data:image/jpeg;base64,${ this .state .image } ` }}
111+ resizeMode= " contain"
112+ / >
70113 < / View>
71114 );
72115 }
73116}
74-
75117```
76118
77119## Properties
78120
79- | Prop | Default | Type | Description |
80- | :-------- | :----: | :--------: | :----------|
81- | overlayColor | ` none ` | ` string ` | Color of the detected rectangle : rgba recommended |
82- | detectionCountBeforeCapture | ` 5 ` | ` integer ` | Number of correct rectangle to detect before capture |
83- | detectionRefreshRateInMS | ` 50 ` | ` integer ` | Time between two rectangle detection attempt |
84- | enableTorch | ` false ` | ` bool ` | Allows to active or deactivate flash during document detection |
85- | useFrontCam | ` false ` | ` bool ` | Allows you to switch between front and back camera |
86- | brightness | ` 0 ` | ` float ` | Increase or decrease camera brightness. Normal as default. |
87- | saturation | ` 1 ` | ` float ` | Increase or decrease camera saturation. Set ` 0 ` for black & white |
88- | contrast | ` 1 ` | ` float ` | Increase or decrease camera contrast. Normal as default |
89- | quality | ` 0.8 ` | ` float ` | Image compression. Reduces both image size and quality |
90- | useBase64 | ` false ` | ` bool ` | If base64 representation should be passed instead of image uri's |
91- | saveInAppDocument | ` false ` | ` bool ` | If should save in app document in case of not using base 64 |
92- | captureMultiple | ` false ` | ` bool ` | Keeps the scanner on after a successful capture |
121+ | Prop | Platform | Default | Type | Description |
122+ | :-------------------------- | :------: | :-----: | : -------: | :---------------------------------------------------------------- |
123+ | overlayColor | Both | ` none ` | ` string ` | Color of the detected rectangle : rgba recommended |
124+ | detectionCountBeforeCapture | iOS | ` 5 ` | ` integer ` | Number of correct rectangle to detect before capture |
125+ | detectionRefreshRateInMS | iOS | ` 50 ` | ` integer ` | Time between two rectangle detection attempt |
126+ | enableTorch | Both | ` false ` | ` bool ` | Allows to active or deactivate flash during document detection |
127+ | useFrontCam | iOS | ` false ` | ` bool ` | Allows you to switch between front and back camera |
128+ | brightness | iOS | ` 0 ` | ` float ` | Increase or decrease camera brightness. Normal as default. |
129+ | saturation | iOS | ` 1 ` | ` float ` | Increase or decrease camera saturation. Set ` 0 ` for black & white |
130+ | contrast | iOS | ` 1 ` | ` float ` | Increase or decrease camera contrast. Normal as default |
131+ | quality | iOS | ` 0.8 ` | ` float ` | Image compression. Reduces both image size and quality |
132+ | useBase64 | iOS | ` false ` | ` bool ` | If base64 representation should be passed instead of image uri's |
133+ | saveInAppDocument | iOS | ` false ` | ` bool ` | If should save in app document in case of not using base 64 |
134+ | captureMultiple | iOS | ` false ` | ` bool ` | Keeps the scanner on after a successful capture |
93135
94136## Manual capture
95137
96138- First get component ref
139+
97140``` javascript
98- < DocumentScanner ref= {( ref ) => this .scanner = ref} / >
141+ < DocumentScanner ref= {ref => ( this .scanner = ref) } / >
99142```
100143
101144- Then call :
145+
102146``` javascript
103147this .scanner .capture ();
104148```
105149
106- ## Each rectangle detection
150+ ## Each rectangle detection (iOS only)
151+
107152| Props | Params | Type | Description |
108- | ------------------- | ---------------------------------------- | ---------- | ------------- |
153+ | ----------------- | -------------------------------------- | -------- | ----------- |
109154| onRectangleDetect | ` { stableCounter, lastDetectionType } ` | ` object ` | See below |
110155
111156The returned object includes the following keys :
@@ -117,30 +162,22 @@ Number of correctly formated rectangle found (this number triggers capture once
117162- ` lastDetectionType `
118163
119164Enum (0, 1 or 2) corresponding to the type of rectangle found
165+
1201660 . Correctly formated rectangle
1211671 . Wrong perspective, bad angle
122- 2 . Too far
123-
168+ 1 . Too far
124169
125170## Returned image
126171
127- | Prop | Params | Type | Description |
128- | :----------- | :-------: | :--------: | : ----------|
129- | onPictureTaken | ` data ` | ` object ` | Returns the captured image in an object ` { croppedImage: ('URI or BASE64 string'), initialImage: 'URI or BASE64 string', rectangleCoordinates: 'object of coordinates' } ` |
172+ | Prop | Params | Type | Description |
173+ | :------------- | :----: | : ------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
174+ | onPictureTaken | ` data ` | ` object ` | Returns the captured image in an object ` { croppedImage: ('URI or BASE64 string'), initialImage: 'URI or BASE64 string', rectangleCoordinates: 'object of coordinates' } ` |
130175
131176## Save in app document
132177
133- ![ Demo save document] ( images/demoSaveDocument.png )
134-
135178If you want to use saveInAppDocument options, then don't forget to add those raws in .plist :
179+
136180``` xml
137181<key >LSSupportsOpeningDocumentsInPlace</key >
138182<true />
139183```
140-
141- ### If you prefer manual installation
142-
143- 1 . In XCode, in the project navigator, right click ` Libraries ` ➜ ` Add Files to [your project's name] `
144- 2 . Go to ` node_modules ` ➜ ` react-native-pdf-scanner ` and add ` RNPdfScanner.xcodeproj `
145- 3 . In XCode, in the project navigator, select your project. Add ` libRNPdfScanner.a ` to your project's ` Build Phases ` ➜ ` Link Binary With Libraries `
146- 4 . Run your project (` Cmd+R ` )<
0 commit comments