- Data Matrix
- Customizing the Barcode color
- Customizing the Barcode dimension
- Customizing the text
Contact Support
Datamatrixgenerator in EJ2 JavaScript Barcode control
5 Mar 202510 minutes to read
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.
var barcode = new ej.barcodegenerator.DataMatrixGenerator
(
{
width: '200px',
height: '150px',
displayText: { visibility: false },
mode: 'SVG',
value: 'Syncfusion',
}
);
barcode.appendTo('#element');
<!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="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<style>
.barcodeStyle{
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style><script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container" class="barcodeStyle">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</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 .
var barcode = new ej.barcodegenerator.DataMatrixGenerator
(
{
width: '200px',
height: '200px',
displayText: { visibility: false },
mode: 'SVG',
value: 'Syncfusion',
foreColor:'red',
}
);
barcode.appendTo('#element');
<!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="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<style>
.barcodeStyle{
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style><script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container" class="barcodeStyle">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Customizing the Barcode dimension
The dimension of the barcode can be changed using the height and width property of the barcodegenerator.
var barcode = new ej.barcodegenerator.DataMatrixGenerator
(
{
width: '100px',
height: '100px',
displayText: { visibility: false },
mode: 'SVG',
value: 'Syncfusion',
}
);
barcode.appendTo('#element');
<!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="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<style>
.barcodeStyle{
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style><script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container" class="barcodeStyle">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Customizing the text
In barcode generators you can customize the barcode text by using the display text property .
var barcode = new ej.barcodegenerator.DataMatrixGenerator
(
{
width: '200px',
height: '200px',
displayText: { visibility: true },
mode: 'SVG',
value: 'Syncfusion',
}
);
barcode.appendTo('#element');
<!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="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<style>
.barcodeStyle{
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style><script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container" class="barcodeStyle">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>