Thanks for downloading Dynamsoft Barcode Reader Package!
Your download will start shortly. If your download does not begin, click here to retry.
Dynamsoft Barcode Reader JavaScript SDK (hereafter called “the library”) provides a built-in GUI to help developers build an interactive barcode reading interface.
The following official sample demonstrates the default GUI built into the library.
GUI Elements
If you check the GUI on the demo page, you will find that it consists of the following elements
There are a few other elements
As mentioned above, the default UI comes with quite a few elements. Some of them might not fit the style of your own application. The following code snippet removes the camera selector, the resolution selector, the close button as well as changes the backgournd color.
document.getElementById('UIElement').appendChild(scanner.getUIElement());
document.querySelector('#UIElement div').style.background = '';
document.getElementsByClassName('dbrScanner-sel-camera')[0].hidden = true;
document.getElementsByClassName('dbrScanner-sel-resolution')[0].hidden = true;
document.getElementsByClassName('dbrScanner-btn-close')[0].hidden = true;
Check out the official sample:
Based on the previous sample, you can build your own UI elements to control the barcode scanning process.
For example, the following code adds a camera selector
<select id="cameraList"></select>
async function updateCameras() {
let cameras = await scanner.getAllCameras();
let cameraList = document.getElementById('cameraList');
cameraList.options.length = 0;
for (let camera of cameras) {
let opt = new Option(camera.label, camera.deviceId);
cameraList.options.add(opt);
}
}
document.getElementById('cameraList').onchange = async function() {
try {
await scanner.setCurrentCamera(document.getElementById('cameraList').value);
} catch (ex) {
alert('Play video failed: ' + (ex.message || ex));
}
};
For more related customization, check out the following official sample:
The library is usually used on mobile devices which have small screens. When scanning barcodes with the mobile camera, the video stream will be limited in the video element and may not be clear enough. Ideally, we should use the whole screen to play the video and find barcodes.
The GUI is pure HTML, so changing the size of the element is very easy. For example, the following enlarges the element to be the full size of the viewport.
document.getElementById('UIElement').style.height = '100vh';
document.getElementById('UIElement').style.width = '100vw';
document.getElementById('UIElement').style.position = 'absolute';
Check out the following sample on how to enlarge the video stream to read a barcode and then change it back to its normal size.
latest version