Skip to main content

Scanning a barcode from an image | Web Barcode Scanner

async detectBarcodes(base64: string, detectionParameters): Promise<BarcodeScannerResultWithSize>

ScanbotSDK 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 an imported .pdf file.

See the API reference 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">

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. See the API reference for details on its properties.

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get your free Trial License

What do you think of this documentation?