Classic UI for the Web Document Data Extractor Module
Integration
Quick start
For the minimal setup to integrate the Document Data Extractor into your web application, either a containerId or a container element is required, and you'll also want to define a callback function to process the detected data.
loading...
Configuration
The Document Data Extractor takes an instance of DocumentDataExtractorViewConfiguration as its argument.
This is your main object for configuration options, styling and receiving the results.
Base configuration
The configuration object inherits base properties shared by all scanner configurations:
containerId: Theidof the containing HTML element where your scanner view will be initialized.videoConstraints: The desired video resolution. Optional, defaults to1920x1080.mirrored: Whether the screen should be mirrored. Useful with user-facing cameras.falseby default.preferredCamera: Camera label or camera device ID. If not available, a default camera is used as a fallback.onError: Callback when something went wrong. Optional.
Advanced configuration
loading...
For details,please refer to the API documentation
Result callback
loading...
Please refer to the API documentation for a description of all its fields.
Styling
Viewfinder-based scanners all have the following two top-level configuration properties:
finder?: ViewFinderConfiguration;
userGuidance?: UserGuidanceConfiguration;
Viewfinder
The finder property controls the styling of the background and the hole.
Its style property can be of either FinderCorneredStyle or FinderStrokedStyle (defaults to FinderCorneredStyle).
Both of them have the following properties and default values:
/** Color of the viewfinder corner's outlines. @defaultValue "#FFFFFFFF"; */
public strokeColor: string = "#FFFFFFFF";
/** Width of the viewfinder corner's outlines. @defaultValue 3.0; */
public strokeWidth: number = 3.0;
/** Radius of the viewfinder's corners. @defaultValue 10.0; */
public cornerRadius: number = 10.0;
If you're configuring the scanner from a JSON object, be sure to include the type name:
finder: {
style: {
_type: "FinderStrokedStyle",
}
},
The finder's size and position can be controlled via the minimumInsets and preferredHeight properties.
If you set minimumInsets, the finder will be placed at the specified minimum distance from the edges of the screen:
.minimumInsets = { top: 0, left: 100, right: 100, bottom: 0 };
Alternatively, if you prefer to keep the finder at the center of the screen, you can set the preferredHeight property
to increase or decrease the size of the finder. This will preserve the default or custom aspectRatio values:
.preferredHeight = 50;
Your entire finder configuration object might look something like this:
const config = {
...
finder: {
visible: true,
style: {
_type: "FinderStrokedStyle",
cornerRadius: 50,
strokeColor: "green",
strokeWidth: 5,
},
aspectRatio: {
width: 16,
height: 9,
},
overlayColor: "rgba(0, 0, 0, 0.5)",
} as ViewFinderConfiguration
};
Alternatively, you can configure the object line by line:
config.finder!.style._type = "FinderStrokedStyle";
config.finder!.style.cornerRadius = 20;
...
User guidance
The userGuidance property is for styling the hint text below the finder window and has the following options:
/** Whether the user guidance is visible. @defaultValue true; */
public visible: boolean = true;
/** Title of the user guidance. @defaultValue new StyledText({ "color": "?sbColorOnPrimary" }); */
public title: StyledText = new StyledText({ "color": "?sbColorOnPrimary" });
/** Background style used for the user guidance.
public background: BackgroundStyle = new BackgroundStyle({ "strokeColor": "#00000000", "fillColor": "?sbColorSurfaceLow" });
Your entire userGuidance configuration object might look something like this:
const config = {
...
userGuidance: {
visible: true,
title: {
text: "Scan item",
color: "white",
},
background: {
strokeColor: "green",
fillColor: "rgba(0, 255, 0, 0.2)",
}
} as UserGuidanceConfiguration
};
Alternatively, you can also configure the object line by line:
config.userGuidance!.title.text = "Scan item";
config.userGuidance!.title.color = "white";
...
The scanner object
To open the Document Data Extractor, simply call the relevant SDK function with the configuration object:
loading...
To improve the handling scanner results, the Scanbot SDK offers the following convenience functions to pause and resume detection while you are processing the data on your side:
scanner.resumeDetection(): void;
scanner.pauseDetection(): void;
scanner.isDetectionPaused(): boolean;
Switching between the front and rear camera
scanner.swapCameraFacing(force?: boolean): void;
swapCameraFacing(true) indicates that only the swapped camera (e.g., the front camera) is acceptable. If the swapped camera is not available, or the user declines the permission to use that camera, the media request will fail.
Firefox on Android: Due to current Firefox browser limitations, we highly recommend checking the running browser and disabling this feature for Firebox browsers.
Switching to a specific available camera
scanner.fetchAvailableCameras(): Promise<CameraInfo[]>;
scanner.switchCamera(deviceId: string, mirrored?: boolean): void;
scanner.getActiveCameraInfo(): CameraInfo | undefined;
interface CameraInfo {
deviceId: string;
label: string;
facingMode?: CameraFacingMode;
supportsTorchControl?: boolean;
}
type CameraFacingMode = 'front' | 'back' | 'unknown';
You can search for available cameras on the running browser by using the fetchAvailableCameras method of a scanner.
You can retrieve the label, device ID, and the camera facing mode information of the active camera of a scanner by using the getActiveCameraInfo method.
You can also switch to another available camera by utilizing its device ID with the switchCamera method.
// There can be no cameras available, so check if cameras is not null
const cameras = await scanner.fetchAvailableCameras()
// Current camera info can be unavailable, so check if currentCameraInfo is not null
const currentCameraInfo = scanner.getActiveCameraInfo();
const cameraIndex = cameras.findIndex((cameraInfo) => {
return cameraInfo.deviceId == currentCameraInfo.deviceId;
});
const newCameraIndex = (cameraIndex + 1) % (cameras.length);
scanner.switchCamera(cameras[newCameraIndex].deviceId);
Controlling the torch (flashlight)
On some mobile devices, the browser can control the torch (flashlight).
Check scanner.getActiveCameraInfo().supportsTorchControl to see if the browser can control the torch for the currently active camera.
If true, you can control the torch by using the setTorchState method of the scanner.
scanner.setTorchState(state: boolean): Promise<void>;
On Android devices, only Chrome supports torch control. Starting with iOS 17.4, all supported browsers on iOS offer torch control functionality.
Want to scan longer than one minute?
Generate a free trial license to test the Scanbot SDK thoroughly.
Get free trial license