Document Scan
Last updated
Last updated
This component can be found under the Sybrin.Identity
namespace and is called DocumentScanComponent
.
Full name: Sybrin.Identity.DocumentScanComponent
.
It is a component that wraps the identity data extraction detection functionality provided by the Sybrin Identity JavaScript API and presents it in the form of a simple UI. It's recommended that you use this component if you do not wish to create your own UI and simply want to use the identity data extraction functionality provided by the Sybrin Identity Web SDK.
With default styling, the document scan component appears as follows:
Upon initializing, the user's camera will start and the component will display a video feed while waiting for the user to center their document inside the rectangle. This action can be cancelled, resulting in the onScanCancelled
event firing.
If an error occurs, the onScanError
event will fire.
If liveness detection completes, the onScanResult
event will fire.
The document scan component can be initialized using the following
code:
The Sybrin Web SDK provides the option to either pass down the ID of the element you wish to use for component initialization, or to pass the element directly.
Please note that 'document-scan' is just an example in this context and the ID may be changed as desired as long as it matches the value passed down during component initialization in JavaScript.
During initialization, the document scan component allows for a number of configuration options that may be passed down using an object literal. The parameters that may be used on the object include the following:
Required:
id (string)
: ID of the element you wish to use for component initialization. Not required if element
is passed.
element (HTMLElement)
: Element you wish to use for component initialization. Not required if id
is passed.
api (Sybrin.Identity.API)
: Instance of a JavaScript API that may be pre-configured as desired. Not required if an instance of options
is passed.
options (Sybrin.Identity.Options)
: Configuration options to instantiate Sybrin.Identity.Api
with. Not required if an instance of api
is passed.
documentTypeId (string)
: An ID that points to a unique document type for a specific country. Not required if countryCode
and documentTypeName
are specified.
countryCode (string)
: The Alpha-3 standard country code of the document to be scanned. Not required if documentTypeId
is passed.
documentTypeName (string)
: The document type to be scanned. Please see document type overrides and filtering for a list of supported document type names. Not required if documentTypeId
is passed.
Optional:
correlationId (string)
: Unique identifier for the case that will be passed down to the back-end if set.
deviceId (string)
: ID of a specific device to use for data extraction.
translations ({ [key: string]: string })
: An object literal representing a dictionary lookup that will be used for translating the component. Please see the translations section on this page for a list of all translatable text, as well as the localization page for a detailed description on how to implement localization.
Warning: Initialization will fail if the intended host element does not exist yet.
Always ensure that the initialize function is only called after the DOM is loaded.
The document scan component may be removed from the UI by calling the destroy()
function on it.
Example:
initialize(): void
Initializes the component's DOM and events.
destroy(): void
Destroys the component's DOM and events.
setTranslations(translations?: { [key: string]: string; }): void
Changes the component's translations to the provided values and updates the DOM accordingly.
setCorrelationId(value: string): void
Sets the component correlation ID (that will be provided to the JavaScript API and sent to the backend) to the provided value.
The document scan component offers multiple events. To hook onto an event, simply assign a function to it.
The following options are available:
onScanResult(result: DocumentScanResult)
onScanError(error: string)
onScanCancelled()
onBeforeScan()
onBeforeUpload()
This function is called when a scan result is acquired without error. To hook onto the event, you may use the following code:
The result parameter is of type Sybrin.Identity.DocumentScanResult
and includes the following properties:
success (boolean)
: Whether or not data could be extracted.
message (string)
: Additional information when applicable, for instance an error message if one occurred.
data (object)
: An object with all data fields that were successfully extracted.
images (object)
: An object with images. These include
documentImage (string)
: Base64 string of the front photo of the document.
documentBackImage (string)
: Base64 string of the back photo of the document (if supplied).
portraitImage (string)
: Base64 string of the extracted face portrait image pulled from the document.
This function is called when something goes wrong and an error occurs during data extraction. To hook onto the event, you may use the following code:
The error parameter is of type string.
This function is called when a document scan for data extraction was started, but then cancelled before completion. To hook onto the event, you may use the following code:
No parameter is passed to this function call.
This function is called before the camera feed is launched when document scan starts. It is recommended to use this function to set the correlationId
of the component by calling setCorrelationId()
. To hook onto the event, you may use the following code:
No parameter is passed to this function call.
This function is called before the file upload window appears. It is recommended to use this function to set the correlationId
of the component by calling setCorrelationId()
. To hook onto the event, you may use the following code:
No parameter is passed to this function call.
The document scan component is structured a follows:
The classes and elements specified above may be used to freely style the document scan component as desired. To do so, simply create a stylesheet and include it in the project, then style according to the above classes and elements.
Styling implementation example:
This component is affected by the following translation keys:
Additionally, the component is affected by the following keys as a result of the JavaScript API applying DOM changes to the UI while liveness is in progress:
Translation Key | Description | Default/Source |
---|---|---|
Translation Key | Description | Default/Source |
---|---|---|
sy-i-translation-53
Caption of the button that cancels document scan and navigates back
Cancel
sy-i-translation-41
Text prompt to display while document scan is initializing
Preparing...
sy-i-translation-42
Text prompt to display when the SDK is looking for the front side of the ID document
Please hold the document up to the camera
sy-i-translation-43
Text prompt to display when the SDK is looking for the rear side of the ID document
Please flip the document over for rear photo
sy-i-translation-44
Text prompt to display when more light is needed
Lighting conditions too dark
sy-i-translation-45
Text prompt to display when there is too much light
Lighting conditions too bright
sy-i-translation-46
Text prompt to display when the image is not clear enough
Image too blurry
sy-i-translation-47
Alert message to show if the SDK detects that the browser is not supported
Browser is not supported.
sy-i-translation-48
Alert message to show if the SDK detects that the user is using a third party browser on an Apple device that doesn't allow camera access to third party browsers.
Browser is not supported. Please open in Safari.
sy-i-translation-68
Caption of the button that dismisses the alert window that is shown when a compatibility issue is detected
Ok