1

I am fairly new to Ionic development and thus far has not run into too many problems. However, I am stuck on trying to get PDF417 type bar-codes to scan (using phonegap-plugin-barcodescanner), despite the documentation suggesting that they are supported via pass the "PDF_417" parameter in the "formats" option. Note: the scanning works on other codes such as QR_CODE, EAN_13 - So the code is mostly right. I don't think that the options list after the error function is being processed.

  $cordovaBarcodeScanner.scan().then(function(imageData) {

    $scope.si_data_display = imageData.text;
    console.log("app.js :: .controller - MainCtrl :: scan_barcode :: text : " + imageData.text);
    console.log("app.js :: .controller - MainCtrl :: scan_barcode :: format : " + imageData.format);
    console.log("app.js :: .controller - MainCtrl :: scan_barcode :: cancelled  : " + imageData.cancelled);

  }, function(error) {
    //TODO: better error handling...
    alert("Error with BarcodeScanner" + error);
  },
  { //I DONT THINK THIS IS WORKING!
    "preferFrontCamera" : true, // iOS and Android
    "showFlipCameraButton" : true, // iOS and Android
    "prompt" : "zzzzzzzzzzzz", // supported on Android only
    "formats" : "PDF_417", // default: all but PDF_417 and RSS_EXPANDED
  });

Any help, suggestion and or pointers will be gratefully received.

Thank you in advance, Harold Clements

  • Which device you test, according to document it only support for Android, WinPhone . I think it's just Beta version, so need to download the source code not install dicrectly by npm. – Rai Vu Nov 11 '16 at 14:30
  • Thank for the reply - Sorry, should have mentioned that in the original post... Its an Android (Samsung S6). – haroldjclements Nov 11 '16 at 14:47
  • You can try this plugin : https://github.com/PDF417/pdf417-phonegap – Rai Vu Nov 11 '16 at 14:50
  • Thank you for your suggestions. In the end, I hard coded the plugin with the all the available formats, which has worked. – haroldjclements Nov 11 '16 at 18:20
  • You should add to the answer what did you do for the next poor guy. Cheers. – Rai Vu Nov 12 '16 at 04:14
  • So can you please elaborate what you did exactly to get it working? i am unable to make it work. – Johal Apr 03 '17 at 21:48

1 Answers1

1

Yes, you have badly written the code, you have an error in the $cordovaBarcodeScanner.scan() funtion, because it is a promise, therefore it returns two callbackFuntion from .them method

q.resolve(result);

q.reject(err);

$CordovaBarcodeScanner ia a factory that returns two functiosns

A function with an input argument

scan: function (config) {

and the secondone with two input arguments

encode: function (type, data) {}

bouth are promise functios

so the correct way to make the request is:

document.addEventListener("deviceready", function () {
$scope.scan= function () {

  $cordovaBarcodeScanner
    .scan({ //I KNOW THIS IS GOOD!
           "preferFrontCamera" : true, // iOS and Android
           "showFlipCameraButton" : true, // iOS and Android
           "prompt" : "zzzzzzzzzzzz", // supported on Android only
           "formats" : "PDF_417"  //NO ',' in the last element
          })
    .then(function (imageData) {
      $scope.si_data_display = imageData.text;
      alert(JSON.stringify(imageData));
    }, function (error) {
      $scope.result=" :( intentalo de nuevo. Ocurrio un Error"
      alert(Error);
    });
}
  /*
    try to use, but inject in your controller
    $ionicPlatform.ready(function() {
      $cordovaBarcodeScanner.scan().then(success, error);
    });
  */

in your html

<button class="button" ng-click="scan()">Escanear</button>

Reviewing the ios library, it only contains the following types of formats, so it does not work for iOS. If you find some method to scan PDF417 in ios using IONIC, you can share it!

typedef enum BarcodeFormat {
    BarcodeFormat_None = 0,
    BarcodeFormat_QR_CODE,
    BarcodeFormat_DATA_MATRIX,
    BarcodeFormat_UPC_E,
    BarcodeFormat_UPC_A,
    BarcodeFormat_EAN_8,
    BarcodeFormat_EAN_13,
    BarcodeFormat_CODE_128,
    BarcodeFormat_CODE_39,
    BarcodeFormat_ITF
} BarcodeFormat;

I hope it will be useful for everyone

Danny Mora
  • 11
  • 3