Barcode Generator is a cordova plugin that allows generation of barcodes like QRCODE, CODE128 etc.
This project is a fork of the original project from Attendee which I would like to thank for his work, it saved me a lot of time.
The Android part of this plugin has been partially rewritten to enhences features and correct some bugs of the original project.
A minimal browser version has been added and supports generation of QRCodes thanks to the qrcodejs library developped by davidshimjs:
https://davidshimjs.github.io/qrcodejs/
Android part is using google zxing library.
- Android Version >= 4.0
- HTML5 browsers
- iOS Version >= 8.0 (Not tested)
First download the last stable version (or master tree) from git in a folder called 'cordova-plugins':
cd cordova-plugins
git clone https://github.com/fefc/cordova-plugin-barcodegenerator.git
Now go to your cordova project folder and install the plugin as follows:
cordova plugin add ../path-to-folder/cordova-plugins/cordova-plugin-barcodegenerator
If you are using ionic framework:
ionic cordova plugin add ../path-to-folder/cordova-plugins/cordova-plugin-barcodegenerator
Done!
Parameter | Description | Default value |
---|---|---|
content | String that will be encoded as a barcode | DefaultBarcode |
height | Height in pixels | 128 |
width | Width in pixels | 128 |
foregroundColor | Color of the bars in HTML | #000000 |
backgroundColor | Background color in HTML | #FFFFFF |
format | Desired barcode type | 11 |
Barcode Type | Enum value | Android | iOS | Browser |
---|---|---|---|---|
AZTEC | 0 | ✔️ | ❔ | ❌ |
CODABAR | 1 | ✔️ | ❔ | ❌ |
CODE_39 | 2 | ✔️ | ❔ | ❌ |
CODE_93 | 3 | ✔️ | ❔ | ❌ |
CODE_128 | 4 | ✔️ | ❔ | ❌ |
DATA_MATRIX | 5 | ✔️ | ❔ | ❌ |
EAN_8 | 6 | ✔️ | ❔ | ❌ |
EAN_13 | 7 | ✔️ | ❔ | ❌ |
ITF | 8 | ✔️ | ❔ | ❌ |
MAXICODE | 9 | ✔️ | ❔ | ❌ |
PDF_417 | 10 | ✔️ | ❔ | ❌ |
QR_CODE | 11 | ✔️ | ❔ | ✔️ |
RSS_14 | 12 | ✔️ | ❔ | ❌ |
RSS_EXPANDED | 13 | ✔️ | ❔ | ❌ |
UPC_A | 14 | ✔️ | ❔ | ❌ |
UPC_E | 15 | ✔️ | ❔ | ❌ |
UPC_EAN_EXTENSION | 16 | ✔️ | ❔ | ❌ |
Following code is issued from the original fork, untested
in *.js that you want to use this.
var success = function(message) { alert(message); };
var error = function(message) { alert("Oopsie! " + message); };
var barcode = cordova.require("com.attendee.barcodegenerator.BarcodeGenerator");
barcode.generate(success,error,"12345");
The plugin will return base64 string of barcode image for using in cordova.
If you are using Ionic 3 you can access the plugin from your typescript code by adding the following line after your imports:
declare var BarcodeGenerator: any;
You can now use the BarcodeGenerator module in your code like:
BarcodeGenerator.generate({
content: 'my barcode content',
height: 512,
width: 512,
format: 11, //Set Features for desired format
foregroundColor: '#000000',
backgroundColor: '#FFFFFF'
},
function(base64barcode) {
console.log("Success!");
},
function(error) {
console.log("Error");
});