Datamatrixgenerator in React Barcode component
Data Matrix
DataMatrix Barcode is a two dimensional barcode that consists of a grid of dark and light dots or blocks forming square or rectangular symbol. The data encoded in the barcode can either be numbers or alphanumeric. They are widely used in printed media such as labels and letters. You can read it easily with the help of a barcode reader and mobile phones.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { DataMatrixGeneratorComponent } from '@syncfusion/ej2-react-barcode-generator';
ReactDOM.render(<DataMatrixGeneratorComponent id="barcode" width={"200px"} height={"150px"} value='Syncfusion'></DataMatrixGeneratorComponent>, document.getElementById("barcode"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { DataMatrixGeneratorComponent } from '@syncfusion/ej2-react-barcode-generator';
ReactDOM.render(
<DataMatrixGeneratorComponent
id="barcode"
width={"200px"}
height={"150px"}
value='Syncfusion'
></DataMatrixGeneratorComponent>,
document.getElementById("barcode")
);<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion® React Chart-DataLabel</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
.barcodeStyle{
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
</head>
<body>
<div id='barcode'class="barcodeStyle">
<div id='loader'>Loading....</div>
</div>
</body>
</html>Customizing the Barcode color
A page or printed media with barcode often appears colorful in the background and surrounding region with other contents. In such cases the barcode can also be customized to suit the needs. You can achieve this by using the foreColor property .
import * as React from "react";
import * as ReactDOM from "react-dom";
import { DataMatrixGeneratorComponent } from '@syncfusion/ej2-react-barcode-generator';
ReactDOM.render(<DataMatrixGeneratorComponent id="barcode" width={"200px"} height={"150px"} foreColor={"red"} value='Syncfusion'></DataMatrixGeneratorComponent>, document.getElementById("barcode"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { DataMatrixGeneratorComponent } from '@syncfusion/ej2-react-barcode-generator';
ReactDOM.render(
<DataMatrixGeneratorComponent
id="barcode"
width={"200px"}
height={"150px"}
foreColor={"red"}
value='Syncfusion'
></DataMatrixGeneratorComponent>,
document.getElementById("barcode")
);<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion® React Chart-DataLabel</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
.barcodeStyle{
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
</head>
<body>
<div id='barcode'class="barcodeStyle">
<div id='loader'>Loading....</div>
</div>
</body>
</html>Customizing the Barcode dimension
The dimension of the barcode can be changed using the height and width property of the barcode generator.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { DataMatrixGeneratorComponent } from '@syncfusion/ej2-react-barcode-generator';
ReactDOM.render(<DataMatrixGeneratorComponent id="barcode" width={"100px"} height={"100px"} value='Syncfusion'></DataMatrixGeneratorComponent>, document.getElementById("barcode"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { DataMatrixGeneratorComponent } from '@syncfusion/ej2-react-barcode-generator';
ReactDOM.render(
<DataMatrixGeneratorComponent
id="barcode"
width={"100px"}
height={"100px"}
value='Syncfusion'
></DataMatrixGeneratorComponent>,
document.getElementById("barcode")
);<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion® React Chart-DataLabel</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
.barcodeStyle{
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
</head>
<body>
<div id='barcode'class="barcodeStyle">
<div id='loader'>Loading....</div>
</div>
</body>
</html>GS1 Data Matrix
GS1 Data Matrix is a standardized Data Matrix barcode format that uses GS1 Application Identifiers (AIs) to encode structured business information such as product identifiers, batch numbers, expiration dates, and serial numbers.
The enableGS1 property enables GS1-compliant Data Matrix barcode generation.
Allowed Input Characters: GS1 Data Matrix supports numeric, alphanumeric, and supported special characters. Data is encoded using GS1 Application Identifiers (AIs), enabling structured business information such as product identifiers, batch numbers, expiration dates, and serial numbers to be stored within a compact barcode.
The following example demonstrates how to generate a GS1 Data Matrix barcode:
import * as React from "react";
import * as ReactDOM from "react-dom";
import { BarcodeGeneratorComponent } from '@syncfusion/ej2-react-barcode-generator';
// GS1 Data Matrix with product identifier, expiration date, and lot number
ReactDOM.render(
<BarcodeGeneratorComponent
id="barcode"
width="300px"
height="250px"
type="DataMatrix"
value="(01)09506000134369(17)280131(10)LOT001"
mode="SVG"
displayText=
enableGS1={true}
></BarcodeGeneratorComponent>,
document.getElementById("barcode")
);import * as React from "react";
import * as ReactDOM from "react-dom";
import { BarcodeGeneratorComponent } from '@syncfusion/ej2-react-barcode-generator';
// GS1 Data Matrix with product identifier, expiration date, and lot number
ReactDOM.render(
<BarcodeGeneratorComponent
id="barcode"
width="300px"
height="250px"
type="DataMatrix"
value="(01)09506000134369(17)280131(10)LOT001"
mode="SVG"
displayText=
enableGS1={true}
></BarcodeGeneratorComponent>,
document.getElementById("barcode")
);<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Barcode</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="React UI Controls" />
<meta name="author" content="Syncfusion" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
.barcodeStyle{
height: 250px;
width: 300pxpx;
padding-left: 40%;
padding-top: 9%;
}
</style>
</head>
<body>
<div id='barcode' class="barcodeStyle">
<div id='loader'>Loading....</div>
</div>
</body>
</html>
Note: The Barcode Generator validates the input data before generating the barcode. If the input data is invalid or cannot be encoded using the selected settings, the
invalidevent is triggered.
Common Validation Errors
| Error | Cause | Solution |
|---|---|---|
| Data too long | Exceeds symbol capacity | Reduce data or change encoding |
| Empty value | No data provided | Supply at least one character |
| Invalid encoding | Unsupported encoding mode | Use Auto, ASCII, ASCIINumeric, or Base256 |
| Invalid character for mode | Character not allowed in selected mode | Change encoding or data |
The following example demonstrates how to handle validation errors:
import * as React from "react";
import * as ReactDOM from "react-dom";
import { BarcodeGeneratorComponent } from '@syncfusion/ej2-react-barcode-generator';
// GS1 Data Matrix with validation handling
const handleInvalid = (args) => {
console.log('Data Matrix validation error: ' + args.message);
// Examples of validation errors:
// - "The data is too long for the specified Data Matrix symbol size."
// - "Data Matrix accepts valid ASCII characters."
};
ReactDOM.render(
<BarcodeGeneratorComponent
id="barcode"
width="200px"
height="150px"
type="DataMatrix"
value="SYNCFUSION"
mode="SVG"
enableGS1={true}
invalid={handleInvalid}
></BarcodeGeneratorComponent>,
document.getElementById("barcode")
);import * as React from "react";
import * as ReactDOM from "react-dom";
import { BarcodeGeneratorComponent } from '@syncfusion/ej2-react-barcode-generator';
// GS1 Data Matrix with validation handling
const handleInvalid = (args) => {
console.log('Data Matrix validation error: ' + args.message);
// Examples of validation errors:
// - "The data is too long for the specified Data Matrix symbol size."
// - "Data Matrix accepts valid ASCII characters."
};
ReactDOM.render(
<BarcodeGeneratorComponent
id="barcode"
width="200px"
height="150px"
type="DataMatrix"
value="SYNCFUSION"
mode="SVG"
enableGS1={true}
invalid={handleInvalid}
></BarcodeGeneratorComponent>,
document.getElementById("barcode")
);<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Barcode</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="React UI Controls" />
<meta name="author" content="Syncfusion" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
.barcodeStyle{
height: 150px;
width: 200pxpx;
padding-left: 40%;
padding-top: 9%;
}
</style>
</head>
<body>
<div id='barcode' class="barcodeStyle">
<div id='loader'>Loading....</div>
</div>
</body>
</html>Customizing the text
In barcode generators you can customize the barcode text by using the display text property .
import * as React from "react";
import * as ReactDOM from "react-dom";
import { DataMatrixGeneratorComponent } from '@syncfusion/ej2-react-barcode-generator';
ReactDOM.render(<DataMatrixGeneratorComponent id="barcode" width={"200px"} height={"150px"} displayText={{ text: "text" }} value='Syncfusion'></DataMatrixGeneratorComponent>, document.getElementById("barcode"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { DataMatrixGeneratorComponent } from '@syncfusion/ej2-react-barcode-generator';
ReactDOM.render(
<DataMatrixGeneratorComponent
id="barcode"
width={"200px"}
height={"150px"}
displayText={{ text: "text" }}
value='Syncfusion'
></DataMatrixGeneratorComponent>,
document.getElementById("barcode")
);<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion® React Chart-DataLabel</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
.barcodeStyle{
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
</head>
<body>
<div id='barcode'class="barcodeStyle">
<div id='loader'>Loading....</div>
</div>
</body>
</html>