To use the print functionality, we should set the allowPrint
property to true. The rendered linear gauge can be printed directly from the browser by calling the method print
.
var gauge = new ej.lineargauge.LinearGauge({
allowPrint: true
}, '#element');
document.getElementById('print').onclick = () => {
gauge.print();
};
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</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">
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container" style="margin-top: 20%;">
<div id="element" style="margin-top: 20%;"></div>
<button id="print" type="button" width="15%" style="float: right">Print</button>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
To use the image export functionality, we should set the allowImageExport
property to true. The rendered linear gauge can be exported as an image using the export
method. The method requires two parameters: image type and file name. The gauge can be exported as an image in the following formats.
var gauge = new ej.lineargauge.LinearGauge({
allowImageExport: true
}, '#element');
document.getElementById('export').onclick = () => {
gauge.export("PNG","Gauge");
};
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</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">
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container" style="margin-top: 20%;">
<div id="element" style="margin-top: 20%;"></div>
<button id="export" type="button" width="15%" style="float: right">Export</button>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
We can get the image file as base64 string for the JPEG and PNG formats. The linear gauge can be exported to image as a base64 string using the export
method. There are four parameters required: image type, file name, orientation of the exported PDF document which must be set as null for image export and finally allowDownload which should be set as false to return base64 string.
var gauge = new ej.lineargauge.LinearGauge({
allowImageExport: true
}, '#element');
document.getElementById('export').onclick = () => {
gauge.export('JPEG', 'Gauge', null, false).then((data) => {
var base64 = data;
document.writeln(base64);
});
};
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</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">
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container" style="margin-top: 20%;">
<div id="element" style="margin-top: 20%;"></div>
<button id="export" type="button" width="15%" style="float: right">Export</button>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
To use the PDF export functionality, we should set the allowPdfExport
property to true. The rendered linear gauge can be exported as PDF using the export
method. The export
method requires three parameters: file type, file name and orientation of the PDF document. The orientation setting is optional and “0” indicates portrait and “1” indicates landscape.
var gauge = new ej.lineargauge.LinearGauge({
allowPdfExport: true
}, '#element');
document.getElementById('export').onclick = () => {
gauge.export("PDF", "Gauge", 0);
};
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</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">
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container" style="margin-top: 20%;">
<div id="element" style="margin-top: 20%;"></div>
<button id="export" type="button" width="15%" style="float: right">Export</button>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Note: The exporting of the linear gauge as base64 string is not supported in the PDF export.