Linear gauge print and export in EJ2 TypeScript Linear gauge control

19 Apr 20239 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 and inject the Print module in Linear Gauge.

import { LinearGauge, Print } from '@syncfusion/ej2-lineargauge';
LinearGauge.Inject(Print);

let gauge: LinearGauge = new 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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <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>
</body>

</html>

Export

Image Export

To use the image export functionality, set the allowImageExport property as true and inject the ImageExport module in Linear Gauge. 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
import { LinearGauge, ImageExport } from '@syncfusion/ej2-lineargauge';
LinearGauge.Inject(ImageExport);

let gauge: LinearGauge = new 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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <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>
</body>

</html>

PDF Export

To use the PDF export functionality, set the allowPdfExport property as true and inject the PdfExport module in Linear Gauge. 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.

import { LinearGauge, PdfExport } from '@syncfusion/ej2-lineargauge';
LinearGauge.Inject(PdfExport);
let gauge: LinearGauge = new 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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <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>
</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.

import { LinearGauge, ImageExport } from '@syncfusion/ej2-lineargauge';
LinearGauge.Inject(ImageExport);
let gauge: LinearGauge = new LinearGauge({
    allowImageExport: true
}, '#element');
document.getElementById('export').onclick = () => {
        gauge.export('JPEG', 'Gauge', null, false).then((data) => {
            let 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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <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>
</body>

</html>

The exporting of the Linear Gauge as base64 string is not applicable for the SVG format.