NeutrinosPlatform / cordova-plugin-document-scanner

cordova plugin for document scan
https://www.neutrinos.co/
MIT License
85 stars 61 forks source link
android cordova document ios scanner

cordova-plugin-document-scanner npm version

DOCUMENTATION - This doc explains the use of plugin ver 4.x.x. For documentation of ver 3.x.x of the plugin, please see the branch ver/3.x.x on github. For ver 2.x.x and below please read the documentation within each of the npm releases.

This plugin defines a global scan object, which provides an API to scan the document using camera (iOS and Android) or by choosing an image from the system's photo library (Android). The plugin does provide edge detection while scanning.

Although the object is attached to the global scoped window, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    console.log(scan);
}

Supported Platforms

Installation

cordova plugin add cordova-plugin-document-scanner@4.x.x

Plugin versions 2.x.x and below are now deprecated. Please use 4.x.x for a stable releases and 3.x.x if you want to be able to use the WeScan Swift library. This requires cordova 7.1.0+ and cordova android 6.4.0+

npm link :- https://www.npmjs.com/package/cordova-plugin-document-scanner

4.x.x uses IRLDocumentScanner ios scan Library (Objective C) - More stable because cordova works seamlessly with objective C

3.x.x uses WeScan ios scan Library (Swift)

Please read issues and fixes section of readme for Ionic & PhoneGap installation

Usage

scan.scanDoc(successCallback, errorCallback, options)

Takes a photo using the scan plugin, or retrieves a photo from the device's image gallery. The image is passed to the document scanner and the scanned image is passed to success callback as the URI for the image file.

The scan.scanDoc function opens the device's camera that allows users to snap pictures by default. Once the user snaps the photo, the scan application closes and the application is restored.

successCallback

errorCallback

options

Plugin adds file:// in front of the imageuri returned for both android and ios.
iOS example imageURI returned :- file:///var/mobile/Containers/Data/Application/8376778A-983B-4FBA-B21C-A4CFDD047AAA/Documents/image.jpg
Android example imageURI returned :- file:///storage/emulated/0/Pictures/1563790575755.jpg

Example

scan.scanDoc(successCallback, errorCallback, options);

options example

{
    sourceType : 1,
    fileName : "myfile",
    quality : 2.5,
    returnBase64 : true
}

working example

Take a photo and retrieve the image's file location. Options need not be passed in, if the default values are being used.

    scan.scanDoc(successCallback, errorCallback, {sourceType : 1, fileName : "myfilename", quality : 1.0, returnBase64 : false}); 
    // sourceType will by default take value 1 if no value is set | 0 for gallery | 1 for camera. 
    // fileName will take default value "image" if no value set. Supported only on 4.x.x plugin version
    // quality will take default value 1.0 (highest). Lowest value is 5.0. Any value in between will be accepted
    // returnBase64 will take default boolean value false, meaning image URL is returned. If true base64 is returned
    function successCallback(imageData) {
        alert(imageData);
        console.log(imageData);
        //var image = document.getElementById('myImage');
        //image.src = imageData; // Image URL rendering. 
    //image.src = imageData + '?' + Date.now(); // For iOS, use this to solve issue 10 if unique fileName is not set.
    //image.src = "data:image/jpeg;base64," + imageData; // Base64 rendering
    }

    function errorCallback(message) {
        alert('Failed because: ' + message);
    }

iOS Quirks

Android Quirks

Issues and Fixes

Expand to view the most common issues and their workarounds.

- Error:Execution failed for task ':app:transformNativeLibsWithStripDebugSymbolForDebug'
Delete local ndk-bundle folder. Example location :- C:\Users\Administrator\AppData\Local\Android\sdk\ndk-bundle - CropViewController fails in Xcode due to Incompatible Swift Versions
Refer issue [13](https://github.com/NeutrinosPlatform/cordova-plugin-document-scanner/issues/13) - Couldn't find "libopencv_java3.so" [Problem mainly with 64 bit build devices]
Refer issue [8](https://github.com/NeutrinosPlatform/cordova-plugin-document-scanner/issues/8) - iOS scan UI buttons documentation
Refer issue [15](https://github.com/NeutrinosPlatform/cordova-plugin-document-scanner/issues/15) - Adding plugin in Ionic
Refer 6th response in issue [17](https://github.com/NeutrinosPlatform/cordova-plugin-document-scanner/issues/17) - Adding plugin in PhoneGap
Refer entire issue [22](https://github.com/NeutrinosPlatform/cordova-plugin-document-scanner/issues/22) - iOS: multiple scan does not override the first image
Refer entire issue [10](https://github.com/NeutrinosPlatform/cordova-plugin-document-scanner/issues/10) - Multiple scans don't override the first image | Browser caching issue
Refer issue [10](https://github.com/NeutrinosPlatform/cordova-plugin-document-scanner/issues/10)
- If you are using WKWebView for iOS please follow the workaround in the following issue.
Refer issue [56](https://github.com/NeutrinosPlatform/cordova-plugin-document-scanner/issues/56)

Credits / Native library links

Android :- AndroidScanner

iOS [4.x.x] :- IRLDocumentScanner

iOS [3.x.x] :- WeScan

Huge thanks to these authors for making their document scanning native libraries public.

More about us!

Find out more or contact us directly here :- http://www.neutrinos.co/

Facebook :- https://www.facebook.com/Neutrinos.co/

LinkedIn :- https://www.linkedin.com/company/25057297/

Twitter :- https://twitter.com/Neutrinosco

Instagram :- https://www.instagram.com/neutrinos.co/