Search results

Print and Export in JavaScript (ES5) Linear Gauge control

22 Jul 2021 / 3 minutes to read

Print

The rendered linear gauge can be printed directly from the browser by calling the print method. To use the print functionality, set the allowPrint property as ”true“.

Source
Preview
index.js
index.html
Copied to clipboard
var gauge = new ej.lineargauge.LinearGauge({
        allowPrint: true
}, '#element');

document.getElementById('print').onclick = () => {
        gauge.print();
};
Copied to clipboard
<!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>

Export

Image Export

To use the image export functionality, set the allowImageExport property as ”true”. The rendered linear gauge can be exported as an image using the export method. This method requires two parameters: export type and file name. The Linear Gauge can be exported as an image with the following formats.

  • JPEG
  • PNG
  • SVG
Source
Preview
index.js
index.html
Copied to clipboard
var gauge = new ej.lineargauge.LinearGauge({
        allowImageExport: true
}, '#element');

document.getElementById('export').onclick = () => {
        gauge.export("PNG","Gauge");
};
Copied to clipboard
<!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>

PDF Export

To use the PDF export functionality, set the allowPdfExport property as ”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 of the PDF document can be set as ”Portrait” or ”Landscape“.

Source
Preview
index.js
index.html
Copied to clipboard
var gauge = new ej.lineargauge.LinearGauge({
        allowPdfExport: true
}, '#element');

document.getElementById('export').onclick = () => {
        gauge.export("PDF", "Gauge", 0);
};
Copied to clipboard
<!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>

Exporting Linear Gauge as base64 string of the file

The Linear Gauge can be exported as base64 string for the JPEG, PNG and PDF formats. The rendered Linear Gauge can be exported as base64 string of the exported image or PDF document used in the export method. The arguments that are required for this method is export type, file name, orientation of the exported PDF document and ”allowDownload” boolean value that is set as ”false” to return base64 string. The value for the orientation of the exported PDF document is set as ”null” for image export and ”Portrait” or ”Landscape” for the PDF document.

Source
Preview
index.js
index.html
Copied to clipboard
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);
        });
};
Copied to clipboard
<!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 applicable for the SVG format.