Scanning a barcode from an image file with the Web Barcode Scanner SDK
async detectBarcodes(
image: string | Image,
config: BarcodeScannerConfiguration = {},
consumeType: ConsumeType = 'COPY_IMAGE'
): Promise<Config.BarcodeScannerResult>
The Scanbot SDK provides a handy API to detect barcodes on still images.
In conjunction with third-party libraries such as PDF.js, it can be used very effectively to also detect barcodes from imported PDF files.
Please refer to the API documentation for details on the config and return types.
To test it out for yourself, simply create a basic file picker:
<input class="file-picker" type="file" accept="image/jpeg" width="48" height="48">
Then reference it in your script tag or file and listen to events:
picker.onchange = (e) => {
e.preventDefault();
let reader = new FileReader();
let file = e.target.files[0];
// Be sure to read it as a data url. ScanbotSDK expects a base64 string
reader.readAsDataURL(file);
reader.onload = async (e) => {
const result = await scanbotSDK.detectBarcodes(reader.result);
console.log("barcode detection result", result);
};
};
The result will be a standard BarcodeScannerResultWithSize that is also the result of Barcode Scanner UI.
Please refer to the API documentation for details on its properties.
Want to scan longer than one minute?
Generate a free trial license to test the Scanbot SDK thoroughly.
Get free trial license