I'm trying to get the Pdf417Scanner plugin (https://github.com/PDF417/pdf417-phonegap) to work with Cordova/PhoneGap.
Here's what I've done so far.
- Created a new project using PhoneGap (with Framework7 for the UI)
- Added the plugin, using the command
phonegap plugin add pdf417-phonegap
- Added the Android platform using the command
phonegap platform add android
Snippet of JavaScript code that calls Pdf417Scanner, to scan. Most of this code is straight from their Github project documentation.
$$(document).on('deviceready', function() {
console.log("Device is ready!");
$$('#scan').on('click', function () {
console.log("Inside the scan click");
var types = ["PDF417", "QR Code"];
/**
* Initiate scan with options
* NOTE: Some features are unavailable without a license
* Obtain your key at http://pdf417.mobi
*/
var options = {
beep : true, // Beep on
noDialog : true, // Skip confirm dialog after scan
uncertain : false, //Recommended
quietZone : false, //Recommended
highRes : false, //Recommended
inverseScanning: false,
frontFace : false
};
var licenseiOs = "sRwAAAEQbW9iaS5wZGY0MTcuZGVtbz/roBZ34ygXMQRMupTjSPXnoj0Mz1jPfk1iRX7f78Ux6a+pfXVyW0HCjPTxl5ocxgXWF66PTrtFUbJFCDUpyznreSWY4akvhvqVFfcTYgVEKjB+UqO6vPD5iIaUCaEYhF4dVmM=";
// This license is only valid for package name "mobi.pdf417.demo"
var licenseAndroid = "sRwAAAAQbW9iaS5wZGY0MTcuZGVtb2uCzTSwE5Pixw1pJL5UEN7nyXbOdXB61Ysy/sgAYt4SaB0T/g6JvisLn6HtB8LzLDmpFjULMxmB8iLsy3tFdHtMhLWOM6pr0tQmSLGyhrXfe6rVoHAxJtPrFEoCNTk4RjLltQ==";
cordova.plugins.pdf417Scanner.scan(
// Register the callback handler
function callback(scanningResult) {
// handle cancelled scanning
if (scanningResult.cancelled == true) {
myApp.alert("Cancelled!");
return;
}
// Obtain list of recognizer results
var resultList = scanningResult.resultList;
var resToShow = "";
// Iterate through all results
for (var i = 0; i < resultList.length; i++) {
// Get individual resilt
var recognizerResult = resultList[i];
resToShow += "(Result type: " + recognizerResult.resultType + ") <br>"
if (recognizerResult.resultType == "Barcode result") {
// handle Barcode scanning result
var raw = "";
if (typeof(recognizerResult.raw) != "undefined" && recognizerResult.raw != null) {
raw = " (raw: " + hex2a(recognizerResult.raw) + ")";
}
resToShow += "(Barcode type: " + recognizerResult.type + ")<br>"
+ "Data: " + recognizerResult.data + "<br>"
+ raw;
} else if (recognizerResult.resultType == "USDL result") {
// handle USDL parsing result
var fields = recognizerResult.fields;
resToShow += /** Personal information */
"USDL version: " + fields[kPPStandardVersionNumber] + "; " +
"Family name: " + fields[kPPCustomerFamilyName] + "; " +
"First name: " + fields[kPPCustomerFirstName] + "; " +
"Date of birth: " + fields[kPPDateOfBirth] + "; " +
"Sex: " + fields[kPPSex] + "; " +
"Eye color: " + fields[kPPEyeColor] + "; " +
"Height: " + fields[kPPHeight] + "; " +
"Street: " + fields[kPPAddressStreet] + "; " +
"City: " + fields[kPPAddressCity] + "; " +
"Jurisdiction: " + fields[kPPAddressJurisdictionCode] + "; " +
"Postal code: " + fields[kPPAddressPostalCode] + "; " +
/** License information */
"Issue date: " + fields[kPPDocumentIssueDate] + "; " +
"Expiration date: " + fields[kPPDocumentExpirationDate] + "; " +
"Issuer ID: " + fields[kPPIssuerIdentificationNumber] + "; " +
"Jurisdiction version: " + fields[kPPJurisdictionVersionNumber] + "; " +
"Vehicle class: " + fields[kPPJurisdictionVehicleClass] + "; " +
"Restrictions: " + fields[kPPJurisdictionRestrictionCodes] + "; " +
"Endorsments: " + fields[kPPJurisdictionEndorsementCodes] + "; " +
"Customer ID: " + fields[kPPCustomerIdNumber] + "; ";
}
resToShow += "<br><br>";
}
myApp.alert(resToShow);
},
// Register the error callback
function errorHandler(err) {
myApp.alert('Error: ' + err);
},
types, options, licenseiOs, licenseAndroid
);
});
});
It does get to the console.log("Inside the scan click");
part; but not sure what happens after it hits cordova.plugins.pdf417Scanner.scan
- it just doesn't work. Just to clarify, I test this straight on my Android phone (using Android 7).
Any ideas? Has anyone used this library/plugin?