Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-com-gists/6fc020ff4becc4c21b8ee167210e8eb7 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/6fc020ff4becc4c21b8ee167210e8eb7 to your computer and use it in GitHub Desktop.
Generate Barcode in Node.js
// create barcode generator
let generator = new BarcodeGenerator(EncodeTypes.AZTEC, "Aspose.BarCode");
// set barcode's back color
generator.getParameters().setBackColor("#A9A9A9");
// set barcode's bar color
generator.getParameters().getBarcode().setBarColor("#FFA500");
// set border color
generator.getParameters().getBorder().setColor("#000000");
// set text color
generator.getParameters().getBarcode().getCodeTextParameters().setColor("#FFA500");
// set image resolution
generator.getParameters().setResolution(300);
// save barcode
generator.save("barcode.png", "PNG");
// set barcode's type
let encode_type = EncodeTypes.CODE_128;
// create barcode generator
let generator = new BarcodeGenerator(encode_type, null);
// set text
generator.setCodeText("Aspose.BarCode");
// generate barcode
generator.save("barcode.png", "PNG");
// set barcode's type
let encode_type = EncodeTypes.QR;
// create barcode generator
let generator = new BarcodeGenerator(encode_type, null);
// set text
generator.setCodeText("Aspose.BarCode");
// generate barcode
generator.save("barcode.png", "PNG");
@vladkras
Copy link

vladkras commented Aug 3, 2021

npm install aspose.barcode is not working on Node 12

installations fails with error

(node:40) UnhandledPromiseRejectionWarning: TypeError [ERR_STREAM_NULL_VALUES]: May not write null values to stream

@ahsaniqbalsidiqui
Copy link

@vladkras,
We have tried this scenario with the latest version of NodeJS but could not observe this issue. Could you please test the scenario with the latest version and share the feedback? We are also trying to establish the environment for Node 12 and will share our feedback after testing it.

@vladkras
Copy link

vladkras commented Aug 5, 2021

@ahsaniqbalsidiqui, it's pretty easy to reproduce:

$ docker run --rm -it node:12 bash
# npm install aspose.barcode

@ahsaniqbalsidiqui
Copy link

I have installed node:12 as suggested by you and then followed the rest of the steps mentioned here:
https://docs.aspose.com/barcode/java/aspose-barcode-for-node-js-via-java-installation/#linux

No issue is observed and aspose.barcode is installed successfully using command npm install aspose.barcode

For your reference, to install Oracle JDK I followed the steps mentioned below.
https://hirosht.medium.com/install-oracle-jdk-1-8-and-set-environment-variables-in-ubuntu-82443a7b789

For installing Python 3, I used the following command:
sudo apt install python 3.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment