aspose.barcode
v26.8.0
Published
barcode generation and recognition component
Readme
Aspose.BarCode for Node.js via Java
Aspose.BarCode for Node.js via Java is a barcode generation and recognition library for Node.js applications. It uses the java-bridge integration layer to access the Aspose.BarCode for Java engine.
The library supports barcode generation, recognition, configuration of barcode appearance, recognition quality settings, complex barcode standards, and multiple input and output image formats.
Architecture
Aspose.BarCode for Node.js via Java is a barcode generation and recognition library for Node.js applications.
Aspose.BarCode for Node.js via Java is a native Node.js wrapper over the Aspose.BarCode for Java engine.
It uses the java-bridge integration layer to access the Aspose.BarCode for Java engine.
The package communicates with the Java library through the java-bridge runtime.
No manual bridge configuration is required after installation.
Features
Barcode generation
- Generate linear, postal, 2D, and GS1 barcodes.
- Configure barcode size, resolution, rotation, padding, borders, and colors.
- Configure barcode text, captions, fonts, alignment, and location.
- Configure checksums for supported symbologies.
- Set X-dimension and Y-dimension for supported barcode types.
- Configure barcode-specific options for QR, Data Matrix, PDF417, Aztec, MaxiCode, DotCode, Han Xin, and other symbologies.
- Generate barcode images in raster, vector, and document formats.
- Generate barcode images as Base64 strings.
Barcode recognition
- Recognize one or multiple barcodes in an image.
- Recognize 1D, postal, and 2D barcode types.
- Restrict recognition to one or more barcode symbologies.
- Restrict recognition to selected areas of an image.
- Retrieve barcode text, type, confidence, region, and extended parameters.
- Configure recognition quality and performance.
- Read barcode images from file paths or Base64-encoded data.
Complex barcodes
The complexBarcode namespace provides support for complex barcode standards, including:
- Swiss QR Code
- HIBC LIC
- HIBC PAS
- Mailmark
- MaxiCode structured messages
- US driver license data
Requirements
Node.js 18 or later npm Java Runtime Environment 11 or later
The package uses java-bridge to load the Java Virtual Machine into the Node.js process.
Make sure that a compatible Java installation is available on the system. In most environments, java-bridge detects the JVM automatically. If automatic detection fails, configure the JAVA_HOME environment variable or provide the JVM library location explicitly.
On Windows, the Microsoft Visual C++ Redistributable is also required by java-bridge.
A full Java Development Kit is not required for normal package usage. Install a JDK only if you need to compile Java source code or rebuild Java-related components.
Before you start
Make sure the Java runtime is available:
java -versionThe command should report JDK 11 or later.
If Java is not found, install a supported JDK and configure the JAVA_HOME
environment variable.
Installation
Install the package from npm:
npm install aspose.barcodeDon't install java-bridge package. The package automatically installs the required Java bridge.
API structure
The package exports the asposebarcode object. Public API types are grouped into functional namespaces:
const { asposebarcode } = require("aspose.barcode");
const {
BarcodeGenerator,
EncodeTypes,
BarCodeImageFormat
} = asposebarcode.generation;
const {
BarCodeReader,
DecodeType,
QualitySettings
} = asposebarcode.recognition;
const {
ComplexBarcodeGenerator,
ComplexCodetextReader
} = asposebarcode.complexBarcode;
const {
License,
BarcodeException
} = asposebarcode;The main namespaces are:
asposebarcode.generation— barcode generation classes, parameters, builders, and enumerations.asposebarcode.recognition— barcode recognition classes, settings, results, and enumerations.asposebarcode.complexBarcode— complex barcode generation and decoding classes.asposebarcode.License— product licensing.asposebarcode.BarcodeException— barcode-specific errors.
Quick start
Generate and recognize a barcode
const { asposebarcode } = require("aspose.barcode");
const {
BarcodeGenerator,
EncodeTypes,
BarCodeImageFormat
} = asposebarcode.generation;
const {
BarCodeReader,
DecodeType
} = asposebarcode.recognition;
const filePath = "code128.png";
const generator = new BarcodeGenerator(
EncodeTypes.CODE_128,
"12367891011"
);
generator.save(filePath, BarCodeImageFormat.PNG);
const reader = new BarCodeReader(
filePath,
null,
DecodeType.CODE_128
);
for (const result of reader.readBarCodes()) {
console.log("Recognized barcode code text: " + result.getCodeText());
console.log("Recognized barcode code type: " + result.getCodeTypeName());
}Define the barcode type and generate an image
const { asposebarcode } = require("aspose.barcode");
const {
BarcodeGenerator,
EncodeTypes,
BarCodeImageFormat
} = asposebarcode.generation;
const generator = new BarcodeGenerator(
EncodeTypes.CODE_128,
"123ABC"
);
generator.save(
"how-to-generate-barcode-image.png",
BarCodeImageFormat.PNG
);Change the codetext after creating a generator
const { asposebarcode } = require("aspose.barcode");
const {
BarcodeGenerator,
EncodeTypes,
BarCodeImageFormat
} = asposebarcode.generation;
const generator = new BarcodeGenerator(
EncodeTypes.CODE_128,
null
);
generator.setCodeText("123ABC");
generator.save("code128.png", BarCodeImageFormat.PNG);Configure recognition quality
const { asposebarcode } = require("aspose.barcode");
const {
BarCodeReader,
DecodeType,
QualitySettings
} = asposebarcode.recognition;
const reader = new BarCodeReader(
"code11.png",
null,
DecodeType.CODE_11
);
reader.setQualitySettings(QualitySettings.getHighPerformance());
for (const result of reader.readBarCodes()) {
console.log(result.getCodeText());
console.log(result.getCodeTypeName());
}Available recognition quality presets include:
QualitySettings.getHighPerformance()QualitySettings.getNormalQuality()QualitySettings.getHighQuality()QualitySettings.getMaxQuality()
Recognize several barcode types
const { asposebarcode } = require("aspose.barcode");
const {
BarCodeReader,
DecodeType
} = asposebarcode.recognition;
const reader = new BarCodeReader(
"barcodes.png",
null,
[DecodeType.CODE_39, DecodeType.CODE_128]
);
for (const result of reader.readBarCodes()) {
console.log("BarCode CodeText: " + result.getCodeText());
console.log("BarCode Type: " + result.getCodeTypeName());
}Recognize all supported barcode types
const { asposebarcode } = require("aspose.barcode");
const {
BarCodeReader,
DecodeType
} = asposebarcode.recognition;
const reader = new BarCodeReader(
"barcodes.png",
null,
DecodeType.ALL_SUPPORTED_TYPES
);
for (const result of reader.readBarCodes()) {
console.log(result.getCodeText());
}Recognize barcodes in a selected image area
Recognition areas can be specified as plain JavaScript objects with x, y, width, and height properties:
const { asposebarcode } = require("aspose.barcode");
const {
BarCodeReader,
DecodeType
} = asposebarcode.recognition;
const recognitionArea = {
x: 0,
y: 0,
width: 500,
height: 300
};
const reader = new BarCodeReader(
"barcodes.png",
[recognitionArea],
DecodeType.ALL_SUPPORTED_TYPES
);
for (const result of reader.readBarCodes()) {
console.log(result.getCodeText());
}A recognition area can also be specified as an array containing x, y, width, and height:
const recognitionArea = [0, 0, 500, 300];Multiple recognition areas can be provided in one array:
const recognitionAreas = [
{ x: 0, y: 0, width: 500, height: 300 },
{ x: 500, y: 0, width: 500, height: 300 }
];Generate a barcode as Base64 data
const { asposebarcode } = require("aspose.barcode");
const {
BarcodeGenerator,
EncodeTypes,
BarCodeImageFormat
} = asposebarcode.generation;
const generator = new BarcodeGenerator(
EncodeTypes.QR,
"Aspose.BarCode"
);
const base64Image = generator.generateBarCodeImage(
BarCodeImageFormat.PNG
);
console.log(base64Image);Recognize a barcode from Base64 data
const fs = require("fs");
const { asposebarcode } = require("aspose.barcode");
const {
BarCodeReader,
DecodeType
} = asposebarcode.recognition;
const base64Image = fs.readFileSync("code128.png").toString("base64");
const reader = new BarCodeReader(
base64Image,
null,
DecodeType.CODE_128
);
for (const result of reader.readBarCodes()) {
console.log(result.getCodeText());
}Licensing
Aspose.BarCode for Node.js via Java works in evaluation mode without a license. To remove evaluation limitations, apply a valid Aspose.BarCode license before using the API: Apply the license once during application startup.
const { asposebarcode } = require("aspose.barcode");
const { License } = asposebarcode;
const license = new License();
license.setLicense("Aspose.BarCode.Java.lic");Supported barcode symbologies
Aspose.BarCode supports generation and recognition for many commonly used barcode symbologies.
Numeric and retail symbologies
- EAN-13
- EAN-8
- UPC-A
- UPC-E
- ISBN
- ISMN
- ISSN
- Interleaved 2 of 5
- Standard 2 of 5
- MSI
- Code 11
- Codabar
- EAN-14
- SSCC-18
- ITF-14
- IATA 2 of 5
Alphanumeric symbologies
- Code 128
- GS1 Code 128
- Code 39
- Code 39 Full ASCII
- Code 93
- Patch Code
- Australia Post
- Italian Post 25
- Matrix 2 of 5
DataBar symbologies
- DataBar Omnidirectional
- DataBar Stacked Omnidirectional
- DataBar Expanded
- DataBar Expanded Stacked
- DataBar Stacked
- DataBar Limited
- DataBar Truncated
Postal symbologies
- Postnet
- Planet
- Royal Mail
- Australia Post
- Singapore Post
- Swiss Post Parcel
- Deutsche Post Identcode
- Deutsche Post Leitcode
2D symbologies
- QR Code
- Micro QR
- Rectangular Micro QR
- Data Matrix
- GS1 Data Matrix
- PDF417
- Compact PDF417
- Micro PDF417
- Aztec
- MaxiCode
- DotCode
- Han Xin
- Code 16K
- Codablock F
The exact available types are exposed through EncodeTypes and DecodeType.
Supported image formats
Input image formats
- JPEG
- TIFF
- PNG
- BMP
- GIF
- EXIF
Images can be supplied as file paths or Base64-encoded strings.
Output image formats
The BarCodeImageFormat enumeration includes:
BarCodeImageFormat.BMPBarCodeImageFormat.GIFBarCodeImageFormat.JPEGBarCodeImageFormat.PNGBarCodeImageFormat.TIFFBarCodeImageFormat.TIFF_IN_CMYKBarCodeImageFormat.EMFBarCodeImageFormat.SVGBarCodeImageFormat.PDF
