Document Processing

This component can be found under the Sybrin.Document namespace and is called DocumentProcessingComponent.

Full name: Sybrin.Document.DocumentProcessingComponent.

It is a component that displays the result of a document capture provided by the Sybrin Document JavaScript API and presents it in the form of a UI component, then allows the user to perform processing operations on it. These currently include:

  • Rotation

  • Cropping

The document capture result may be obtained by either using an instance of the JavaScript API or by using a component such as DocumentCaptureComponent.

This component supports editing multiple images. If an array of images is provided, it will allow the user to cycle through all the images and apply processing to all of them, then emit the onAccept event with an array of all processed images.

With default styling, the Document Processing component appears as follows:

Upon clicking the trashcan button, all changes on the current image will be discarded and it will revert to the original.

Upon clicking the clockwise arrow button, the image will be rotated 90 degrees clockwise.

Upon clicking the anti-clockwise arrow button, the image will be rotated 90 degrees anti-clockwise.

Upon clicking the crop button, the component will enter a cropping mode that allows the user to crop the image.

Upon clicking "Accept Image(s)", the onAccept event will fire.

Upon clicking "Recapture Image(s)", the onRetry event will fire.

Initialization

The document processing component can be initialized using the following code:

<div id='processing'></div>

The Sybrin Web SDK provides the option to either provide the ID of the element you wish to use for component initialization, or to provide the element directly.

Please note that 'processing' is just an example in this context and the ID may be changed as desired as long as it matches the value provided during component initialization in JavaScript.

During initialization, the Document Processing component allows for a number of configuration options that may be provided 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 provided.

  • element (HTMLElement): Element you wish to use for component initialization. Not required if id is provided.

  • dataUris (string[]): Array of data URIs for all the images to be processed.

Optional:

  • cropSelectionStart (Sybrin.Document.CropSelectionStart): Sets how the crop selection area should be initialized. The options are middle (0) and full (1). The middle option sets the crop selection area to start as a smaller block in the center of the image. The full option will initially select the entire image.

  • 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.

  • backButtonMode (string: 'recapture' | 'back' | 'hidden'): Sets back button behavior for the component. 'recapture' will set the text to indicate that images will be recaptured. 'back' will set the text to "Back". 'hidden' will hide the button. Default 'recapture'

Warning: Initialization will fail if the intended host element does not exist yet.

Always ensure that the initialize function is only called once the DOM is loaded.

Destruction

The document processing component may be removed from the UI by calling the "destroy()" function on it.

Example:

component.destroy();

Functions

Initialize

initialize(): void

Initializes the component's DOM and events.

Destroy

destroy(): void

Destroys the component's DOM and events.

Set Translations

setTranslations(translations?: { [key: string]: string; }): void

Changes the component's translations to the provided values and updates the DOM accordingly.

Events

The document crop component offers multiple events. To hook onto an event, simply assign a function to it.

The following options are available:

  • onAccept(croppedDataUris: string[])

  • onRetry()

On Accept

This function is called when the user clicks on the continue button. To hook onto the event, you may use the following code:

component.onAccept = function(croppedDataUris) {
    // Your code here
}

The parameter is an array of data URI strings for all processed image data.

On Retry

This function is called when the user clicks on the retry button. To hook onto the event, you may use the following code:

component.onRetry = function() {
    // Your code here
}

No parameters are provided to this function call.

Styling

The document processing component is structured as follows:

<div class="sybrin-document-document-processing-component sybrin-document-container sybrin-sdk-container">
    <div class="sybrin-document-component-section sybrin-document-toolbar sybrin-document-processing-controls sybrin-sdk-toolbar sybrin-document-center">
        <div class="sybrin-document-toolbar-discard"></div>
        <div class="sybrin-document-toolbar-rotate-right"></div>
        <div class="sybrin-document-toolbar-rotate-left"></div>
        <div class="sybrin-document-toolbar-crop"></div>
    </div>

    <div class="sybrin-document-component-section sybrin-document-toolbar sybrin-document-crop-controls sybrin-sdk-toolbar sybrin-document-center sybrin-hidden">
        <div class="sybrin-document-toolbar-applycrop"></div>
        <div class="sybrin-document-toolbar-cancelcrop"></div>
    </div>

    <div class="sybrin-document-component-section">
        <div class="sybrin-document-editing-count">Editing image 1 of 1</div>
    </div>

    <div class="sybrin-document-component-section sybrin-document-processing-crop-container sybrin-sdk-component-section sybrin-document-center sybrin-hidden">
        <img class="sybrin-document-crop-element" id="selection" />
    </div>

    <div class="sybrin-document-component-section sybrin-document-processing-result-container sybrin-sdk-component-section sybrin-document-center">
        <img class="sybrin-document-processing-result-element" />
    </div>

    <div class="sybrin-document-button-section sybrin-sdk-button-section sybrin-document-processing-main-buttons">
        <button class="sybrin-document-retry sybrin-document-flow-button sybrin-sdk-flow-button sybrin-secondary">Recapture</button>
        <button class="sybrin-document-accept sybrin-document-flow-button sybrin-sdk-flow-button">Accept</button>
    </div>
</div>

The classes and elements specified above may be used to freely style the document processing 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:

index.html
<html>
<head>
    <link rel="stylesheet" type="text/css" href="styles.css" media="screen"/>
</head>
<body>
    <div id='component'></div>
</body>
</html>ult

Translations

Currently, no translations are available.