Search results

Print and Export in JavaScript Linear Gauge control

29 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” and inject the Print module in Linear Gauge.

Source
Preview
index.ts
index.html
Copied to clipboard
import { LinearGauge, Print } from '@syncfusion/ej2-lineargauge';
LinearGauge.Inject(Print);

let gauge: LinearGauge = new 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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></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
Source
Preview
index.ts
index.html
Copied to clipboard
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");
};
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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></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“.

Source
Preview
index.ts
index.html
Copied to clipboard
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);
};
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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></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.

Source
Preview
index.ts
index.html
Copied to clipboard
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);
    });
};
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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></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>

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