NEWSMRZ Scanner is now part of barKoder.What it means for you →

DOCUMENTATION

API description

MRZ Scanner 1.x (archive) / React Native

Documentation / MRZ Scanner 1.x (archive) / React Native

On this page

 

1.In order to interact with module, first thing is to import it into your App.js file and create a reference to it:

 

import {NativeModules} from 'react-native' ;

const MrzScanner = NativeModules.RNMrzScanner;

 

2. To receive results from the scanner , you have to import “NativeEventEmitter” as followed :

 

const EventEmitter = new NativeEventEmitter(MrzScanner);

 

Results are sent as an event by the native module with the following keys:


'successfulScanEmittedEvent' - for MRZ scan


'successfulDocumentScanEmittedEvent' - for document image scan


‘scannerWasDismissedEmittedEvent’ - for dismissed scanner


’permissionsWereDeniedEmittedEvent’ - for denied permission


‘scanImageFailedEmittedEvent’- for a failed image scan
 

JavaScript can then receive the registered event by “add ListenerOn” using the “Subscribe” mixin.

(Use of the eventEmitter can be found in the provided sample project ”Sample.js”.)

 

3. To receive results you need to embed an EventListener in the componentDidMount() life cycle method.

 

-The way the listener works is that it waits for an event to happen under the key  "successfulScanEmittedEvent", in this case, we're getting the results for "body".

-In this case we're using type SCANNER_TYPE.MRZ, 
the results for "body" will also include the following if found :
- body.raw_result (raw String of the scanner MRZ)
- body.portrait (base64 String)
- body.signature (base64 String)
- body.full_image (base64 String)

componentDidMount(){   
      subscription=EventEmitter.addListener
      ('successfulScanEmittedEvent',
        (body) => 
         console.log("Results" + body.surname,
                                 body.document_type_readable,
                                 body.issuing_country,
                                 body.surname,
                                 body.document_number,
                                 body.nationality,
                                 body.dob_raw,
                                 body.dob_readable,
                                 body.sex, )
       );}

 

 To get access to the new functionalities from JavaScript you have to pull them off of NativeModules each time :

const MrzScanner= NativeModules.RNMrzScanner;

MrzScanner.startScanner()

 

 

startScanner

 

Activates the scanner, with a default SCANNER_TYPE.MRZ if not specified.

MrzScanner.startScanner()

 

 

closeScanner

 

 Stop and close the MRZ Scanner

MrzScanner.closeScanner()

 

 

setScannerType


Specify which scanner type you want to use. There are two options: "MRZ Scanner" and "Document Image scanner".
The "MRZ Scanner" option is used to scan for MRZ.
The "Document image scanner" is used for capturing the front and back image of the ID documents.


@param int [SCANNER_TYPE.MRZ,  SCANNER_TYPE.DOCUMENT_IMAGE_ID, SCANNER_TYPE.DOCUMENT_IMAGE_PASSPORT,  SCANNER_TYPE.DRIVING_LICENCE, SCANNER_TYPE.DOCUMENT_IMAGE_ID_FRONT, SCANNER_TYPE.ID_SESSION]. The default value is SCANNER_TYPE.MRZ

MrzScanner.setScannerType(ScannerType  int)

 

 

resumeScanning()

 

Resume scanning after the scanner has been paused/stopped. Usually after a successful scan.

MrzScanner.resumeScanning()

 

 

setDateFormat(String dateFormat)

 

Set the date format in which the parsed dates are formatted.

@return the currently set date format in which the parsed dates are formatted.
@param dateFormat the pattern describing the date format. Example: "dd.MM.yyyy"

MrzScanner.setDateFormat(String dateFormat)

 

 

getSdkVersion

 

@return the current SDK Version.

MrzScanner.getSdkVersion()

 

 

setIDActive

 

Specify whether the scanner should detect and return results for IDs.


@param isIDActive [true, false]. The default value is true.

MrzScanner.setIDActive(isIDActive: Boolean)

 

 

setPassportActive


Specify whether the scanner should detect and return results for passports.


@param isPassportActive [true, false]. The default value is true.

MrzScanner.setPassportActive(isPassportActive: Boolean)

 

 

setVisaActive


Specify whether the scanner should detect and return results for *visas.


@param activate [true, false]. Default value is true.

MrzScanner.setVisaActive(isVisaActive: Boolean)

 

 

setMaxThreads


Specify the maximum number of CPU threads that the scanner can use during the scanning process.


@param int [MAX_THREADS.ONE, MAX_THREADS.TWO, MAX_THREADS.THREE, MAX_THREADS.FOUR, MAX_THREADS.FIVE,
MAX_THREADS.SIX]. The default value is MAX_THREADS.TWO

MrzScanner.setMaxThreads(maxThreads: Int)

 


setEffortLevel


Specify the effort level for the scanner to use during the scanning process.


@param int [EFFORT_LEVEL.CASUAL, EFFORT_LEVEL.TRY_HARDER, EFFORT_LEVEL.SWEATY]. The default value is EFFORT_LEVEL.TRY_HARDER

MrzScanner.setEffortLevel(effortLevel: Int)



setZoomFactor
 

Set the zoom factor for the camera preview.

@param number. Default value is 1.0

MrzScanner.setZoomFactor(zoomFactor: number) 



registerWithLicenseKey


Register with the license key provided to remove the asterisks (*) from the result.


@param key the provided license key.
@return 0 for success, -1 if registration failed.

MrzScanner.registerWithLicenseKey(key: String)

To get your evaluation key today, register an account on https://mrzscanner.com/register

 

 

startScannerWithCustomOverlay

 

Customize the overlay of the finder in the scanner


@param base64String takes a base64 type string 

MrzScanner.startScannerWithCustomOverlay(base64String : String)

 

 

toggleFlash

 

Trigger flashlight.

MrzScanner.toggleFlash(active : Boolean) 

 

 

scanFromGallery

 

 Trigger an image picker.

MrzScanner.scanFromGallery()

 

 

setContinuousScanningEnabled


Initiates the scanner view with continuous scanning enabled.
After a successful scan, the scanner will not be dismissed or paused.
To close the scanner call closeScanner()

See setIgnoreDuplicatesEnabled for further continuous scanning behavior changes.


@param boolean: activate.

MrzScanner.setContinuousScanningEnabled(active : Boolean)

 

 

setIgnoreDuplicatesEnabled


Ignores duplicate is used to specify whether the scanner should ignore *the successful scan if the document number is identical to the previous *successful scan.

@param boolean: activate.

MrzScanner.setIgnoreDuplicatesEnabled(activete : Boolean)

 

 

setVibrateOnSuccessfulScan


Enables vibrate on a successful scan option.


@param boolean: activate.

MrzScanner.setVibrateOnSuccessfulScan(activete : Boolean)

 

setExtractPortraitEnabled

 

Enable automatically extracting portrait image on successful scan; Default value: false.

@param:activated.

MrzScanner.setExtractPortraitEnabled(activated);

 

 

setExtractSignatureEnabled

 

Enable automatically extracting signature image on successful scan; Default value: false.

@param:activated.

MrzScanner.setExtractSignatureEnabled(activated);

 

 

setExtractFullPassportImageEnabled

 

Enable automatically extracting passport image on successful scan; Default value: false.

@param:activated.

MrzScanner.setExtractFullPassportImageEnabled(activated);

 

 

setExtractIdBackImageEnabled

 

Enable automatically extracting ID(back) image on successful scan; Default value: false.

@param:activated.

MrzScanner.setExtractIdBackImageEnabled(activated);

 

 

startPartialViewScanner


Set the scanning rectangle to limit the scanning area.The parameters' values are representing percentages of the scanning preview.


@param x the top-left point of the scanning rectangle. [0,...,100]Default value: 5.
@param y the top-left point of the scanning rectangle. [0,...,100]Default value: 20.
@param width the width of the scanning rectangle. [0,...,100]Default value: 90.
@param height the height of the scanning rectangle. [0,...,100]Default value: 60.

MrzScanner.startPartialViewScanner(Int : x, Int : y, Int : width, Int : height)

 

*Sample apps and more detailed instructions are included with the download file.

Download link: https://mrzscanner.com/download.

Updated Jun 18, 2024 · Questions? Ask us