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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234 | 1×
1×
1×
1×
31×
1×
29×
29×
29×
29×
29×
29×
29×
29×
29×
23×
29×
29×
29×
29×
23×
23×
23×
23×
4×
19×
10×
23×
6×
29×
5×
2×
2×
3×
24×
8×
8×
7×
8×
8×
4×
4×
16×
16×
16×
16×
16×
4×
12×
4×
16×
16×
16×
16×
5×
11×
11×
16×
29×
23×
23×
1×
14×
1×
29×
29×
29×
29×
29×
29×
29×
29×
23×
29×
29×
29×
23×
29×
23×
23×
29×
1×
7×
7×
7×
7×
7×
7×
7×
7×
1×
9×
9×
9×
9×
9×
9×
9×
9×
9×
9×
9×
9×
1×
4×
4×
4×
4×
1×
4×
4×
4×
4×
4×
4×
4×
4×
4×
4×
94316×
4×
4×
4×
4×
1×
2×
2×
2×
2×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-pdf-export", "@syncfusion/ej2-svg-base", "../utils/helper", "@syncfusion/ej2-pdf-export"], function (require, exports, ej2_base_1, ej2_pdf_export_1, ej2_svg_base_1, helper_1, ej2_pdf_export_2) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ExportUtils = (function () {
function ExportUtils(control) {
this.control = control;
}
ExportUtils.prototype.export = function (type, fileName, orientation) {
var _this = this;
var controlValue = this.getControlsValue();
var width = controlValue.width;
var height = controlValue.height;
var element = this.control.svgObject;
var url;
var isCanvas = this.control.enableCanvasRendering;
var image;
if (!isCanvas) {
element = ej2_base_1.createElement('canvas', {
id: 'ej2-canvas',
attrs: {
'width': width.toString(),
'height': height.toString()
}
});
}
var isDownload = !(ej2_base_1.Browser.userAgent.toString().indexOf('HeadlessChrome') > -1);
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">' +
controlValue.svg.outerHTML +
'</svg>';
if (!isCanvas) {
var exportElement = this.control.svgObject.cloneNode(true);
var backgroundElement = exportElement.childNodes[0];
var backgroundColor = backgroundElement.getAttribute('fill');
if ((this.control.theme === 'Tailwind' || this.control.theme === 'Bootstrap5' || this.control.theme === 'Fluent' || this.control.theme === 'Material3' || this.control.theme === 'Fluent2')
&& (backgroundColor === 'rgba(255,255,255, 0.0)' || backgroundColor === 'transparent')) {
backgroundElement.setAttribute('fill', 'rgba(255,255,255, 1)');
}
else if ((this.control.theme === 'TailwindDark' || this.control.theme === 'Bootstrap5Dark' || this.control.theme === 'FluentDark' || this.control.theme === 'Material3Dark' ||
this.control.theme === 'Fluent2Dark' || this.control.theme === 'Fluent2HighContrast')
&& (backgroundColor === 'rgba(255,255,255, 0.0)' || backgroundColor === 'transparent')) {
backgroundElement.setAttribute('fill', 'rgba(0, 0, 0, 1)');
}
url = window.URL.createObjectURL(new Blob(type === 'SVG' ? [svgData] :
[(new XMLSerializer()).serializeToString(exportElement)], { type: 'image/svg+xml' }));
}
else {
url = element.toDataURL('image/png');
}
if (type === 'SVG') {
if (ej2_base_1.Browser.info.name === 'msie') {
var svg = new Blob([(new XMLSerializer()).serializeToString(controlValue.svg)], { type: 'application/octet-stream' });
Iif (!ej2_base_1.isNullOrUndefined(window.navigator.msSaveOrOpenBlob)) {
window.navigator.msSaveOrOpenBlob(svg, fileName + '.' + type.toLocaleLowerCase());
}
}
else {
this.triggerDownload(fileName, type, url, isDownload);
}
}
else if (ej2_base_1.Browser.info.name === 'msie') {
var canvas = element;
if (!isCanvas) {
canvas = this.createCanvas();
}
image = canvas.toDataURL(type);
if (type === 'PDF') {
this.exportPdf(canvas, orientation, width, height, isDownload, fileName);
}
else {
this.doExport(type, image, fileName);
}
}
else {
var image_1 = new Image();
var ctx_1 = element.getContext('2d');
var backgroundColor_1 = ctx_1.shadowColor;
image_1.onload = (function () {
if ((_this.control.theme === 'Tailwind' || _this.control.theme === 'Bootstrap5' || _this.control.theme === 'Fluent' || _this.control.theme === 'Material3' || _this.control.theme === 'Fluent2')
&& (backgroundColor_1 === 'rgba(0, 0, 0, 0)' || backgroundColor_1 === 'transparent')) {
ctx_1.fillStyle = 'rgba(255,255,255, 1)';
}
else if ((_this.control.theme === 'TailwindDark' || _this.control.theme === 'Bootstrap5Dark' || _this.control.theme === 'FluentDark' || _this.control.theme === 'Material3Dark' ||
_this.control.theme === 'Fluent2Dark' || _this.control.theme === 'Fluent2HighContrast')
&& (backgroundColor_1 === 'rgba(0, 0, 0, 0)' || backgroundColor_1 === 'transparent')) {
ctx_1.fillStyle = 'rgba(0, 0, 0, 1)';
}
ctx_1.fillRect(0, 0, element.width, element.height);
ctx_1.drawImage(image_1, 0, 0);
window.URL.revokeObjectURL(url);
if (type === 'PDF') {
_this.exportPdf(element, orientation, width, height, isDownload, fileName);
}
else {
Iif (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(element.msToBlob(), fileName + '.' + type.toLocaleLowerCase());
}
else {
_this.triggerDownload(fileName, type, element.toDataURL('image/png').replace('image/png', 'image/octet-stream'), isDownload);
}
}
});
image_1.src = url;
}
if (!isCanvas) {
var id = document.getElementById(this.control.element.id);
helper_1.removeElement(id + '_canvas');
}
};
ExportUtils.prototype.triggerDownload = function (fileName, type, url, isDownload) {
ej2_base_1.createElement('a', {
attrs: {
'download': fileName + '.' + type.toLocaleLowerCase(),
'href': url
}
}).dispatchEvent(new MouseEvent(isDownload ? 'click' : 'move', {
view: window,
bubbles: false,
cancelable: true
}));
};
ExportUtils.prototype.getControlsValue = function () {
var width = 0;
var height = 0;
var isCanvas = this.control.enableCanvasRendering;
var svgObject = new ej2_svg_base_1.SvgRenderer('').createSvg({
id: 'Svg_Export_Element',
width: 200, height: 200
});
var svg = this.control.svgObject.cloneNode(true);
var groupEle = this.control.renderer.createGroup({});
groupEle.style.cssText = 'transform: translateY(' + height + 'px)';
if (!isCanvas) {
groupEle.appendChild(svg);
}
width = Math.max(this.control.availableSize.width, width);
height = height + this.control.availableSize.height;
if (!isCanvas) {
svgObject.appendChild(groupEle);
}
if (!isCanvas) {
svgObject.setAttribute('width', width + '');
svgObject.setAttribute('height', height + '');
}
return {
'width': width,
'height': height,
'svg': svgObject
};
};
ExportUtils.prototype.createCanvas = function () {
var heatmap = this.control;
var renderMode = heatmap.renderingMode;
heatmap.renderingMode = 'Canvas';
heatmap.refresh();
var canvas = heatmap.svgObject;
heatmap.renderingMode = renderMode;
heatmap.refresh();
return canvas;
};
ExportUtils.prototype.exportPdf = function (element, orientation, width, height, isDownload, fileName) {
var document = new ej2_pdf_export_1.PdfDocument();
var margin = document.pageSettings.margins;
var pdfDefaultWidth = document.pageSettings.width;
var pdfDefaultHeight = document.pageSettings.height;
var imageString = element.toDataURL('image/jpeg').replace('image/jpeg', 'image/octet-stream');
document.pageSettings.orientation = orientation;
var exactWidth = (pdfDefaultWidth < width) ? (width + margin.left + margin.right) : pdfDefaultWidth;
var exactHeight = (pdfDefaultHeight < height) ? (height + margin.top + margin.bottom) : pdfDefaultHeight;
document.pageSettings.size = new ej2_pdf_export_2.SizeF(exactWidth, exactHeight);
imageString = imageString.slice(imageString.indexOf(',') + 1);
document.pages.add().graphics.drawImage(new ej2_pdf_export_1.PdfBitmap(imageString), 0, 0, width, height);
Iif (isDownload) {
document.save(fileName + '.pdf');
document.destroy();
}
};
ExportUtils.prototype.doExport = function (type, image, fileName) {
var images = [];
var fileType = type || 'JPG';
images = [image];
this.exportImage(images, fileName, fileType, image);
};
ExportUtils.prototype.exportImage = function (images, fileName, fileType, image) {
var buffers = [];
var length = (!(images instanceof HTMLElement)) ? images.length : 0;
for (var g = 0; g < length; g++) {
image = images[g];
image = image.replace(/^data:[a-z]*;,/, '');
var image1 = image.split(',');
var byteString = atob(image1[1]);
var buffer = new ArrayBuffer(byteString.length);
var intArray = new Uint8Array(buffer);
for (var i = 0; i < byteString.length; i++) {
intArray[i] = byteString.charCodeAt(i);
}
buffers.push(buffer);
}
for (var j = 0; j < buffers.length; j++) {
var b = new Blob([buffers[j]], { type: 'application/octet-stream' });
Iif (ej2_base_1.Browser.info.name === 'msie' && !ej2_base_1.isNullOrUndefined(window.navigator.msSaveOrOpenBlob)) {
window.navigator.msSaveOrOpenBlob(b, fileName + '.' + fileType.toLocaleLowerCase());
}
}
};
ExportUtils.prototype.print = function () {
this.printWindow = window.open('', 'print', 'height=' + window.outerHeight + ',width=' + window.outerWidth + ',tabbar=no');
this.printWindow.moveTo(0, 0);
this.printWindow.resizeTo(screen.availWidth, screen.availHeight);
if (this.control.renderingMode === 'SVG') {
ej2_base_1.print(this.getHTMLContent(), this.printWindow);
}
else {
var element = this.control.svgObject;
var dataUrl = element.toDataURL();
var image_2 = new Image();
var ctx_2 = element.getContext('2d');
image_2.onload = (function () {
ctx_2.drawImage(image_2, 0, 0);
});
image_2.src = dataUrl;
ej2_base_1.print(image_2, this.printWindow);
}
};
ExportUtils.prototype.getHTMLContent = function () {
var div = ej2_base_1.createElement('div');
div.appendChild(this.control.element.cloneNode(true));
return div;
};
return ExportUtils;
}());
exports.ExportUtils = ExportUtils;
});
|