如何使用离子条码扫描器扫描驾驶执照上的pdf417条码并检索信息?
How can I use the ionic-barcode scanner to scan the pdf417 barcode on the driver licenses and retrive information?
这是从条形码中检索到的JSON。
{"text":"03451736","format":"UPC_E","cancelled":"false"}
IN App main Module添加条码扫描器导入
import { BarcodeScanner, BarcodeScannerOptions } from '@ionic-native/barcode-scanner';
将其添加到供应商数组
providers: [
.....
;;;;; Other providers
;;;;;
BarcodeScanner,
],
并且在组件中
import { BarcodeScanner, BarcodeScannerOptions } from '@ionic-native/barcode-scanner';
在构造函数中初始化
constructor(public barcodeCtrl: BarcodeScanner)
提供扫描选项
const options: BarcodeScannerOptions = {
preferFrontCamera: false,
showFlipCameraButton: false,
showTorchButton: true,
torchOn: false,
prompt: 'Place a barcode inside the scan area',
resultDisplayDuration: 500,
formats: 'QR_CODE,DATA_MATRIX,UPC_A,UPC_E,EAN_8,EAN_13,CODE_39,CODE_93,CODE_128,ITF,PDF_417,AZTEC',
orientation: 'portrait',
disableAnimations: true, // iOS
disableSuccessBeep: false, // iOS and Android
};
在按钮上点击调用下方函数
Scan(){
this.barcodeCtrl.scan(options).then((barcodeData) => {
console.log('Barcode data', barcodeData);
this.licenceData = JSON.parse(barcodeData.text); // This will contain your licence details
}).catch((err) => {
console.log('Error', err);
});
}
这是从条形码中检索到的JSON。
{"text":"03451736","format":"UPC_E","cancelled":"false"}
IN App main Module添加条码扫描器导入
import { BarcodeScanner, BarcodeScannerOptions } from '@ionic-native/barcode-scanner';
将其添加到供应商数组
providers: [
.....
;;;;; Other providers
;;;;;
BarcodeScanner,
],
并且在组件中
import { BarcodeScanner, BarcodeScannerOptions } from '@ionic-native/barcode-scanner';
在构造函数中初始化
constructor(public barcodeCtrl: BarcodeScanner)
提供扫描选项
const options: BarcodeScannerOptions = {
preferFrontCamera: false,
showFlipCameraButton: false,
showTorchButton: true,
torchOn: false,
prompt: 'Place a barcode inside the scan area',
resultDisplayDuration: 500,
formats: 'QR_CODE,DATA_MATRIX,UPC_A,UPC_E,EAN_8,EAN_13,CODE_39,CODE_93,CODE_128,ITF,PDF_417,AZTEC',
orientation: 'portrait',
disableAnimations: true, // iOS
disableSuccessBeep: false, // iOS and Android
};
在按钮上点击调用下方函数
Scan(){
this.barcodeCtrl.scan(options).then((barcodeData) => {
console.log('Barcode data', barcodeData);
this.licenceData = JSON.parse(barcodeData.text); // This will contain your licence details
}).catch((err) => {
console.log('Error', err);
});
}