all files / linear-gauge/model/ pdf-export.js

97.37% Statements 37/38
88% Branches 22/25
100% Functions 8/8
97.37% Lines 37/38
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                                                 386×          
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-pdf-export"], function (require, exports, ej2_base_1, ej2_pdf_export_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfExport = (function () {
        function PdfExport(control) {
        }
        PdfExport.prototype.export = function (gauge, type, fileName, orientation, allowDownload) {
            var promise = new Promise(function (resolve) {
                var canvasElement = ej2_base_1.createElement('canvas', {
                    id: 'ej2-canvas',
                    attrs: {
                        'width': gauge.availableSize.width.toString(),
                        'height': gauge.availableSize.height.toString()
                    }
                });
                orientation = ej2_base_1.isNullOrUndefined(orientation) ? ej2_pdf_export_1.PdfPageOrientation.Landscape : orientation;
                var svgData = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
                    gauge.svgObject.outerHTML +
                    '</svg>';
                var exportElement = gauge.svgObject.cloneNode(true);
                var backgroundElement = exportElement.childNodes[0];
                var backgroundColor = backgroundElement.getAttribute('fill');
                if ((gauge.theme === 'Tailwind' || gauge.theme === 'Bootstrap5' || gauge.theme === 'Fluent' || gauge.theme === 'Material3' ||
                    gauge.theme === 'Fluent2')
                    && (backgroundColor === 'rgba(255,255,255, 0.0)' || backgroundColor === 'transparent')) {
                    exportElement.childNodes[0].setAttribute('fill', 'rgba(255,255,255, 1)');
                }
                else Iif ((gauge.theme === 'TailwindDark' || gauge.theme === 'Bootstrap5Dark' || gauge.theme === 'FluentDark' || gauge.theme === 'Material3Dark' ||
                    gauge.theme === 'Fluent2Dark' || gauge.theme === 'Fluent2HighContrast')
                    && (backgroundColor === 'rgba(255,255,255, 0.0)' || backgroundColor === 'transparent')) {
                    exportElement.childNodes[0].setAttribute('fill', 'rgba(0, 0, 0, 1)');
                }
                var url = window.URL.createObjectURL(new Blob(type === 'SVG' ? [svgData] :
                    [(new XMLSerializer()).serializeToString(exportElement)], { type: 'image/svg+xml' }));
                var image = new Image();
                var context = canvasElement.getContext('2d');
                image.onload = (function () {
                    context.drawImage(image, 0, 0);
                    window.URL.revokeObjectURL(url);
                    var document = new ej2_pdf_export_1.PdfDocument();
                    var imageString = canvasElement.toDataURL('image/jpeg').replace('image/jpeg', 'image/octet-stream');
                    document.pageSettings.orientation = orientation;
                    imageString = imageString.slice(imageString.indexOf(',') + 1);
                    document.pages.add().graphics.drawImage(new ej2_pdf_export_1.PdfBitmap(imageString), 0, 0, (gauge.availableSize.width - 60), gauge.availableSize.height);
                    if (allowDownload) {
                        document.save(fileName + '.pdf');
                        document.destroy();
                    }
                    else {
                        resolve(null);
                    }
                });
                image.src = url;
            });
            return promise;
        };
        PdfExport.prototype.getModuleName = function () {
            return 'PdfExport';
        };
        PdfExport.prototype.destroy = function () {
        };
        return PdfExport;
    }());
    exports.PdfExport = PdfExport;
});