Barcodes are used to visually represent the data in the form of graphical objects. Different types of barcodes are used in various cases, such as Code128, QR code, Aztech, Pdf127, and etc. In this article, you will learn how to implement barcode generation features in your web applications. Particularly, you will learn to develop Node.js Barcode Generator application and you will also learn how to generate QR code in Node.js applications.
- Node.js Barcode Generator API
- Generate a Barcode in Node.js
- Generate a QR Code in Node.js
- Customize Appearance of a Barcode
Node.js Barcode Generator API
In order to generate barcodes, we will use Aspose.BarCode for Node.js via Java. It is a feature-rich API that lets you generate and read popular barcode symbologies from within your Node.js applications. You can either download the API or install it using the following NPM command.
> npm install aspose.barcode
Aspose.BarCode for Node.js via Java supports the following barcode symbologies.
Australia Post | EAN8 |
Aztec | Interleaved2of5 |
BarCode supplement | ITF14 |
BooklandEAN | Matrix 2 of 5 |
Codabar | MSI |
Code11 | Pdf417 |
Code128 | Planet |
Code39 Extended | Postnet |
Code39 Standard | PZN (Pharma Zentral Nummer, Pharmazentralnummer barcode) |
Code93 Extended | QR |
Code93 Standard | SSCC18 |
Datamatrix | Standard2of5 |
Deutsche Post Identcode | Swiss QR |
EAN128 | UPCA |
EAN13 | UPCE |
EAN14(SCC14) |
Generate a Barcode in Node.js
The following are the steps to generate a barcode in Node.js applications.
- First, create an object of BarcodeGenerator class and set the barcode’s type in its constructor, e.g. EncodeTypes.CODE_128.
- Set barcode’s text using BarcodeGenerator.setCodeText(string) method.
- Finally, generate the barcode’s image using BarcodeGenerator.save(string, string) method.
The following code sample shows how to generate a barcode image in Node.js.
Barcode
Generate a QR Code in Node.js
Aspose.BarCode for Node.js via Java also allows you to generate two-dimensional barcodes such as QR codes. The following are the steps to generate a QR code in Node.js.
- First, create an object of BarcodeGenerator class and pass EncodeTypes.QR to its constructor.
- Set QR barcode’s text using BarcodeGenerator.setCodeText(string) method.
- Finally, generate QR code’s image using BarcodeGenerator.save(string, string) method.
The following code sample shows how to generate a QR code in Node.js.
QR Code
Customize Appearance of a Barcode
You can also customize the appearance of a barcode by changing the forecolor, back color, font, border, resolution, etc. The following are the steps to customize the appearance of a barcode.
- First, create an object of BarcodeGenerator class and set the barcode’s type in its constructor, e.g. EncodeTypes.AZTEC.
- Set barcode’s text using BarcodeGenerator.setCodeText(string) method.
- Customize the barcode using its parameters, such as set back color using BarcodeGenerator.getParameters().setBackColor("#A9A9A9") method.
- Finally, generate the barcode’s image using BarcodeGenerator.save(string, string) method.
The following code sample shows how to customize a barcode in Node.js.
Barcode
Get a Free API License
In order to use the API without evaluation limitations, you can get a free temporary license.
Conclusion
In this article, you have learned how to generate a barcode in Node.js applications. Also, you have seen how to customize the appearance of the barcodes using different options. Furthermore, you can explore more about the API using its documentation. In addition, you can share your queries with us via our forum.