all files / spreadsheet/renderer/ print.js

93.56% Statements 683/730
81.33% Branches 662/814
90% Functions 36/40
94.33% Lines 682/723
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 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054   887× 887× 887× 887× 887× 887× 887× 887× 887× 887× 887× 887× 887× 887× 887× 887× 887× 887× 887× 887× 887× 887×   16× 16× 16× 16× 16× 10× 10×     11× 11× 11×                       21× 21× 21× 21×                 21× 21× 21× 21× 21× 21× 21× 21×   26× 26× 26× 26× 26× 26× 26× 26× 26× 26× 26× 31× 31× 31× 31× 31× 31× 31× 31× 31× 31× 31× 31× 31× 31× 31× 31× 31×   31× 1321× 1321× 1321× 1321× 1321× 1321× 1321× 1321× 1321× 1321×   1321×   1321× 11× 11× 11× 11× 11×     116× 70×         1318× 1318× 1318× 22× 223× 223× 223× 223× 245×     245×   245× 241× 241× 241× 241× 241× 241× 241× 241× 241× 22× 22×                 1318×   1308×                           1308×     1308× 11220×   11220× 65×   11220×   10891×       10891×         10891× 10891× 10891× 10891×   10891× 10891× 642× 642× 642× 640× 642× 642×   642× 642×           10891× 9155× 9155× 9155×       9155×                           9155×   9155×     9155×           9155× 9155× 9155× 9155× 9155× 9155×                           9155×     9155× 9155× 16×   9155× 9155×   9155×   9155×   6420× 6420×             6418× 458×         458× 458×   5960× 37×   37× 37×     5923×         5923× 5923× 5923×   6420× 6420× 6420× 6420× 6420× 6420× 6420× 6420× 6420× 99× 99× 99×       99×   99× 99× 99× 99× 99× 99× 99× 121× 121× 121× 121× 121× 121×   99×     6321× 6321× 6321× 6321× 6321× 6321× 6321× 6321× 6321×     6321× 24× 24×   6321× 6321× 6321×       2735×   9155×       30×     10891×   10891× 4092× 4092×   10891× 10891× 10891×                     10891× 861×   10891× 17× 17×   10891× 10883×     329× 219×     219× 219× 219× 219× 218× 218×   218× 218×   219×   11220×   1308× 1308× 11220× 11220×     10× 10× 10×   10× 139×   139×     139×   139× 139× 139× 139× 60×   79×   139× 139×   139×       31× 23× 19×   23× 23× 18×           65× 65× 65× 65× 65×   899× 899× 899× 899× 899× 899× 899× 899× 899× 899× 899× 899× 899× 899×                                                                                 6442×         2735× 2735× 2735× 2735× 2735× 2735× 2735× 2735×   867× 867× 867× 867× 867× 867× 867× 867× 867× 867× 867× 867×   18× 18×     13×     13× 13× 13× 13× 13× 13× 13×   13× 13×                       13× 31× 31× 31× 31× 31× 31× 31× 31× 13× 13× 13× 13× 13×     31× 31×         6176× 6176× 6176× 5302× 5302×   6176× 5274× 5274×   6176× 5723× 5723×   6176× 5276× 5276×     21575× 21575×   21571×   21567× 48× 48×   48×   48×   48×   48×   48×   48×   48×   48×   48× 48× 48×                   40×         36×         32×           26×         22×         18×           12×                                       48× 48×     21519× 21519×   21527× 21527× 21527×   48× 48× 48× 48×   7550× 7550× 7550× 7550× 6306×   839× 839×   1118× 1118×   4349× 4349×     1244×         1244×   7550×   21× 21× 21×   13× 13× 13× 150× 150×   150× 150× 150×     13× 13×   13×   99×     99× 99× 99× 99× 99× 122× 122× 122× 122× 22× 22×     100×     99× 99×   126650×   886× 886× 886×        
define(["require", "exports", "@syncfusion/ej2-base", "../../workbook/index", "../../workbook/index", "../../workbook/index", "../common/index"], function (require, exports, ej2_base_1, index_1, index_2, index_3, index_4) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Print = (function () {
        function Print(parent) {
            this.totalSheetCount = [];
            this.workbookActiveSheetCount = 0;
            this.defaultCellWidth = 64;
            this.defaultCellHeight = 19;
            this.pageCounts = [];
            this.initialRowCount = 0;
            this.chartHeight = 0;
            this.columnIndex = 0;
            this.rowIndex = 0;
            this.multipleCanvasDataURL = [];
            this.chartElements = [];
            this.totalCharts = 0;
            this.isChartLoaded = false;
            this.chartLoadedCount = 0;
            this.isImageLoaded = false;
            this.totalImages = 0;
            this.imageLoadedCount = 0;
            this.endRow = 0;
            this.isColumn = true;
            this.startNewPageCount = 0;
            this.allowTimer = false;
            this.parent = parent;
        }
        Print.prototype.print = function (spreadsheet, printOptions) {
            var _this = this;
            spreadsheet.isPrintingProcessing = true;
            this.multipleCanvasDataURL = [];
            this.chartElements = [];
            if (printOptions.type === 'ActiveSheet') {
                var sheet = spreadsheet.sheets[spreadsheet.activeSheetIndex];
                this.activeSheetPrint(spreadsheet, sheet, printOptions, spreadsheet.activeSheetIndex);
            }
            else {
                this.totalSheetCount = [];
                this.workbookActiveSheetCount = 1;
                for (var i = 0; i < spreadsheet.sheets.length; i++) {
                    Eif (spreadsheet.sheets[i].state === 'Visible') {
                        this.totalSheetCount.push(i);
                        if (this.totalSheetCount.length > 1 && this.parent.sheets[i].ranges.length > 0) {
                            var isDatasourceAvailable = this.parent.sheets[i].ranges.some(function (range) {
                                return !ej2_base_1.isNullOrUndefined(range.dataSource);
                            });
                            Eif (isDatasourceAvailable) {
                                this.allowTimer = true;
                                var sheet = spreadsheet.sheets[i];
                                var address = index_3.getCellAddress(0, 0) + ':' + index_3.getCellAddress(sheet.rowCount - 1, sheet.colCount - 1);
                                var cellIndexes = index_3.getIndexesFromAddress(address);
                                this.parent.notify(index_3.updateSheetFromDataSource, { sheet: sheet, indexes: cellIndexes });
                            }
                        }
                    }
                }
                if (this.allowTimer) {
                    this.allowTimer = false;
                    setTimeout(function () {
                        _this.activeSheetPrint(spreadsheet, spreadsheet.sheets[_this.totalSheetCount[0]], printOptions, _this.totalSheetCount[0]);
                    }, 2000);
                }
                else {
                    this.activeSheetPrint(spreadsheet, spreadsheet.sheets[this.totalSheetCount[0]], printOptions, this.totalSheetCount[0]);
                }
            }
        };
        Print.prototype.updateChartRowAndColumnIndices = function (spreadsheet, sheetIndex) {
            var sheet = spreadsheet.sheets[sheetIndex];
            this.rowIndex = sheet.usedRange.rowIndex;
            this.columnIndex = sheet.usedRange.colIndex;
            if (spreadsheet.chartColl.length > 0) {
                for (var i = 0; i < spreadsheet.chartColl.length; i++) {
                    var chart = spreadsheet.chartColl[i];
                    var sheetIdx = index_1.getSheetIndex(spreadsheet, chart.range.substring(0, chart.range.lastIndexOf('!')));
                    Eif (sheetIndex === sheetIdx) {
                        var chartleft = { clientX: chart.left, isImage: true };
                        var chartTop = { clientY: chart.top, isImage: true };
                        spreadsheet.notify(index_4.getRowIdxFromClientY, chartTop);
                        spreadsheet.notify(index_4.getColIdxFromClientX, chartleft);
                        Iif (chartTop.clientY > sheet.usedRange.rowIndex) {
                            this.rowIndex = Math.max(this.rowIndex, chartTop.clientY);
                        }
                        Iif (chartleft.clientX > sheet.usedRange.colIndex) {
                            this.columnIndex = Math.max(this.columnIndex, chartleft.clientX);
                        }
                    }
                }
            }
        };
        Print.prototype.activeSheetPrint = function (spreadsheet, sheet, printOptions, sheetIndex) {
            this.updateChartRowAndColumnIndices(spreadsheet, sheetIndex);
            this.pageCounts = this.calculatePageCount(sheet, 1000, printOptions.allowRowColumnHeader);
            var canvas;
            var context;
            this.initialRowCount = 0;
            this.parent.currentPrintSheetIndex = sheetIndex;
            this.endRow = this.rowIndex + 1;
            this.processCell(0, 0, this.endRow, 2, [], context, canvas, sheet, this, 0, 0, true, sheetIndex, printOptions);
        };
        Print.prototype.processCell = function (page, rowsCount, rowCount, currentX, currentY, context, canvas, sheet, printInstance, pageHeight, height, isCanvasDataUrl, sheetIndex, printOptions) {
            var _this = this;
            Iif (pageHeight === void 0) { pageHeight = 0; }
            Iif (height === void 0) { height = 0; }
            Iif (isCanvasDataUrl === void 0) { isCanvasDataUrl = true; }
            var defaultCellSpace = 0;
            var allowColumnAndRow = printOptions.allowRowColumnHeader;
            var headerWidth = 37;
            var lineHeight = 0;
            this.chartHeight = 0;
            var isExtraLine = false;
            for (var i = page; i < this.pageCounts.length; i++) {
                this.chartLoadedCount = 0;
                this.totalCharts = 0;
                this.imageLoadedCount = 0;
                this.totalImages = 0;
                pageHeight += (i === 0 ? 0 : 1100);
                canvas = document.createElement('canvas');
                context = canvas.getContext('2d');
                canvas.width = 1000;
                canvas.height = 1100;
                context.font = '11pt Calibri';
                context.textBaseline = 'bottom';
                context['index'] = i;
                context['width'] = 1000;
                Eif (isCanvasDataUrl || (!this.isImageLoaded && !this.isChartLoaded)) {
                    currentY = [];
                    currentX = 0;
                    height = 0;
                }
                for (var j = rowsCount; j < this.endRow; j++) {
                    isCanvasDataUrl = true;
                    var borderOfHeaderText = false;
                    this.isColumn = this.isColumn ? this.isColumn : (j === 0);
                    var bottomStyle = { borderBottom: '1px solid black' };
                    var rowHeight = (sheet.rows[j] && sheet.rows[j].height || this.defaultCellHeight);
                    this.initialRowCount = j;
                    currentX = defaultCellSpace;
                    var start = i === 0 ? 0 : this.pageCounts[i - 1] + 1;
                    var end = this.pageCounts[i];
                    height += (ej2_base_1.isNullOrUndefined(sheet.rows[j]) ? this.defaultCellHeight : rowHeight + (j === 0 && allowColumnAndRow
                        ? this.defaultCellHeight : 0));
                    var cellHeight = ej2_base_1.isNullOrUndefined(sheet.rows[j]) ? this.defaultCellHeight :
                        sheet.rows[j] && sheet.rows[j].height || this.defaultCellHeight;
                    if (height > 1080) {
                        this.startNewPageCount = j;
                        lineHeight = allowColumnAndRow ? rowHeight + (j === 0 && allowColumnAndRow ? this.defaultCellHeight : 0) : 0;
                        borderOfHeaderText = false;
                        this.isColumn = true;
                        if (this.isImageLoaded || this.isChartLoaded) {
                            break;
                        }
                        pageHeight += 1100;
                        Eif (isCanvasDataUrl) {
                            this.multipleCanvasDataURL.push(canvas.toDataURL());
                        }
                        isCanvasDataUrl = true;
                        canvas = document.createElement('canvas');
                        context = canvas.getContext('2d');
                        canvas.width = 1000;
                        canvas.height = 1100;
                        context.font = '11pt Calibri';
                        context.textBaseline = 'bottom';
                        context['index'] = i;
                        context['width'] = 1000;
                        for (var m = 0; m < currentY.length; m++) {
                            if (currentY[m] !== undefined) {
                                currentY[m] -= height - cellHeight;
                            }
                        }
                        height = (allowColumnAndRow || printOptions.allowGridLines) ?
                            rowHeight + (allowColumnAndRow ? this.defaultCellHeight : 0) : rowHeight;
                    }
                    var style = { borderBottom: '1px solid black', borderTop: '1px solid black', borderLeft: '1px solid black', borderRight: '1px solid black' };
                    var rightStyle = { borderRight: '1px solid black' };
                    if (allowColumnAndRow && this.isColumn) {
                        for (var k = start; k <= end; k++) {
                            var columnText = index_3.getColumnHeaderText(k + 1);
                            var columnIndex = k === start ? 2 : 1;
                            context.font = '11pt Calibri';
                            for (var m = 0; m < columnIndex; m++) {
                                var titleWidth = (m === 0 && columnIndex === 2) ? headerWidth : (sheet.columns[k] &&
                                    sheet.columns[k].hidden ? 0 : ((sheet.columns[k] &&
                                    sheet.columns[k].width) || this.defaultCellWidth));
                                titleWidth = currentX + titleWidth > 1000 ? titleWidth - 1 - (currentX + titleWidth - 1000) :
                                    titleWidth;
                                if (titleWidth !== 0) {
                                    var textMetrics = context.measureText(columnText);
                                    var textWidth = textMetrics.width;
                                    var locationX = printInstance.calculateTextPosition(textWidth, titleWidth, currentX, 'Center');
                                    var locationY = this.defaultCellHeight;
                                    context.fillText(k === start && m === 0 ? '' : columnText, locationX, locationY);
                                    printInstance.drawBorder(context, style, currentX, 0, titleWidth, this.defaultCellHeight);
                                    currentX += titleWidth;
                                    currentY[k] = this.defaultCellHeight;
                                    if (k === end && (columnIndex === 2 ? m === 1 : m === 0)) {
                                        this.isColumn = !(k === end);
                                        currentX = 0;
                                    }
                                }
                                else Iif (k === end) {
                                    this.isColumn = false;
                                    currentX = 0;
                                }
                            }
                        }
                    }
                    if (!ej2_base_1.isNullOrUndefined(sheet.rows[j]) && (ej2_base_1.isNullOrUndefined(sheet.rows[j].hidden) ||
                        !sheet.rows[j].hidden)) {
                        Iif (isExtraLine) {
                            var extaSpace = sheet.rows.slice(j, j + sheet.rows.length - j).map(function (row) {
                                return (row && row.height) || _this.defaultCellHeight;
                            }).reduce(function (accumulator, currentValue) {
                                return accumulator + (currentValue || _this.defaultCellHeight);
                            }, 0);
                            if (canvas.height > (height + (this.chartHeight - extaSpace))) {
                                this.endRow += Math.ceil((this.chartHeight - extaSpace) / 19);
                            }
                            else {
                                this.endRow += Math.ceil((canvas.height - (height + extaSpace)) / 19);
                            }
                            isExtraLine = false;
                        }
                        borderOfHeaderText = this.endRow === sheet.rows.length ? ((height + (sheet.rows[j + 1] ?
                            (sheet.rows[j + 1].height || this.defaultCellHeight) : this.defaultCellHeight)) +
                            (j === 0 && allowColumnAndRow ? this.defaultCellHeight : 0) > 1080) || (j === sheet.rows.length - 1) : false;
                        var _loop_1 = function (k) {
                            var cell = sheet.rows[j] && !ej2_base_1.isNullOrUndefined(sheet.rows[j].cells) &&
                                sheet.rows[j].cells[k];
                            if (!ej2_base_1.isNullOrUndefined(cell) && !ej2_base_1.isNullOrUndefined(cell.style)) {
                                style = this_1.setBorderStyle(cell, style);
                            }
                            if (ej2_base_1.isNullOrUndefined(sheet.columns[k]) || ej2_base_1.isNullOrUndefined(sheet.columns[k].hidden) ||
                                !sheet.columns[k].hidden) {
                                var isColumnSpan = !ej2_base_1.isNullOrUndefined(sheet.rows[j].cells) &&
                                    !ej2_base_1.isNullOrUndefined(sheet.rows[j].cells[k]) &&
                                    !isNaN(sheet.rows[j].cells[k].colSpan) &&
                                    start > k + sheet.rows[j].cells[k].colSpan;
                                var isRowSpan = !ej2_base_1.isNullOrUndefined(sheet.rows[j].cells) &&
                                    !ej2_base_1.isNullOrUndefined(sheet.rows[j].cells[k]) &&
                                    !isNaN(sheet.rows[j].cells[k].rowSpan) &&
                                    !(j + sheet.rows[j].cells[k].rowSpan > this_1.startNewPageCount) &&
                                    this_1.startNewPageCount !== 0;
                                var cellText_1 = '';
                                var cellWidthSpan_1;
                                var cellWidth_1;
                                var cellRowSpan = !ej2_base_1.isNullOrUndefined(cell) ? (isNaN(cell.rowSpan) || isColumnSpan || isRowSpan) ? 1 :
                                    Math.max(cell.rowSpan, 0) : 1;
                                currentY[k] = (isNaN(currentY[k]) ? defaultCellSpace : currentY[k]);
                                if (allowColumnAndRow && k === start) {
                                    context.font = '11pt Calibri';
                                    var rowHeaderHeight = currentY[k];
                                    if (cellRowSpan > 0) {
                                        for (var o = 0; o < (cellRowSpan === 0 ? 1 : cellRowSpan); o++) {
                                            currentX = 0;
                                            rowHeaderHeight += (o === 0 ? 0 : (sheet.rows[j + o] && sheet.rows[j + o - 1].height ||
                                                this_1.defaultCellHeight));
                                            printInstance.rowHeaderText((j + 1 + o).toString(), context, printInstance, headerWidth, currentX, style, rowHeaderHeight, sheet.rows[j + o].height || this_1.defaultCellHeight);
                                            currentX += headerWidth;
                                        }
                                    }
                                    else {
                                        currentX = 0;
                                        currentX += headerWidth;
                                    }
                                }
                                if (!ej2_base_1.isNullOrUndefined(cell) && cell) {
                                    var fontSize = (cell.style ? cell.style.fontSize || '11pt' : '11pt');
                                    var color_1 = (cell.style ? cell.style.color || '#000000' : '#000000');
                                    if (!isNaN(sheet.rows[j].cells[k].rowSpan) &&
                                        sheet.rows[j].cells[k].rowSpan > 1) {
                                        if (isNaN(sheet.rows[j + 1].cells[k].rowSpan)) {
                                            this_1.parent.merge("" + index_3.getColumnHeaderText(k + 1) + (j + 1) + ":" + index_3.getColumnHeaderText(k + 1) + (j + sheet.rows[j].cells[k].rowSpan - 1));
                                        }
                                    }
                                    Iif (!isNaN(sheet.rows[j].cells[k].colSpan) &&
                                        sheet.rows[j].cells[k].colSpan > 1) {
                                        if (!ej2_base_1.isNullOrUndefined(sheet.rows[j + 1]) && !ej2_base_1.isNullOrUndefined(sheet.rows[j + 1].cells) &&
                                            sheet.rows[j + 1].cells.length > 0 && (!ej2_base_1.isNullOrUndefined(sheet.rows[j + 1].cells[k]) &&
                                            isNaN(sheet.rows[j + 1].cells[k].colSpan))) {
                                            this_1.parent.merge('' + index_3.getColumnHeaderText(k + 1) + (j + 1) + ':' +
                                                index_3.getColumnHeaderText(k + 1 + sheet.rows[j].cells[k].colSpan - 1) + (j + 1));
                                        }
                                        else if (ej2_base_1.isNullOrUndefined(sheet.rows[j].cells[k + 1].colSpan)) {
                                            for (var m = 1; m < sheet.rows[j].cells[k].colSpan; m++) {
                                                sheet.rows[j].cells[k + m]['colSpan'] = -m;
                                            }
                                        }
                                    }
                                    cellWidthSpan_1 = (isNaN(sheet.rows[j].cells[k].colSpan) || isColumnSpan) ? 1 :
                                        Math.max(sheet.rows[j].cells[k].colSpan, 0);
                                    if (sheet.rows[j].cells[k].rowSpan && !isColumnSpan &&
                                        sheet.rows[j].cells[k].rowSpan < 0) {
                                        var colSpan = sheet.rows[j + sheet.rows[j].cells[k].rowSpan].cells[k].colSpan;
                                        cellWidthSpan_1 = colSpan ? colSpan : cellWidthSpan_1;
                                    }
                                    Iif ((k === start || (k > 0 && sheet.columns && sheet.columns[k - 1] &&
                                        sheet.columns[k - 1].hidden && (sheet.rows[j].cells[k - 1] &&
                                        sheet.rows[j].cells[k - 1].colSpan > 1))) &&
                                        cellWidthSpan_1 <= 0) {
                                        cellWidthSpan_1 = 1;
                                    }
                                    var backgroundColor = (cell.style ? cell.style.backgroundColor || '#ffffff' : '#ffffff');
                                    var textAlign = cell.style ? cell.style['textAlign'] : '';
                                    context.font = fontSize;
                                    context.fillStyle = color_1;
                                    var cellWidthSpanArray_1 = [];
                                    Iif (cellWidthSpan_1 > 1) {
                                        var widthColumn = sheet.columns.slice(k, k + cellWidthSpan_1);
                                        for (var o = 0; o < widthColumn.length; o++) {
                                            cellWidthSpanArray_1.push(widthColumn['hidden'] ? 0 : ((widthColumn[o] && widthColumn[o]['width']) ||
                                                this_1.defaultCellWidth));
                                        }
                                        if (cellWidthSpanArray_1.length === 0) {
                                            cellWidthSpanArray_1.push((this_1.defaultCellWidth * cellWidthSpan_1));
                                        }
                                        else if (cellWidthSpanArray_1.length !== cellWidthSpan_1) {
                                            cellWidthSpanArray_1 = cellWidthSpanArray_1.map(function (value) { return value +
                                                (_this.defaultCellWidth * (cellWidthSpan_1 - 1 - cellWidthSpanArray_1.length)); });
                                        }
                                    }
                                    cellWidth_1 = cellWidthSpan_1 > 1 ? cellWidthSpanArray_1.reduce(function (acc, width) { return acc + width; }, 0) :
                                        cellWidthSpan_1 === 1 ? (sheet.columns[k] && sheet.columns[k].width ||
                                            this_1.defaultCellWidth) : 0;
                                    cellWidth_1 = currentX + cellWidth_1 > 1000 ? cellWidth_1 - 1 - (currentX + cellWidth_1 - 1000) : cellWidth_1;
                                    cellHeight = cellRowSpan > 1 ? sheet.rows.slice(j, j + cellRowSpan).map(function (row) { return row.height ||
                                        _this.defaultCellHeight; }).reduce(function (accumulator, currentValue) { return accumulator +
                                        (currentValue || _this.defaultCellHeight); }, 0) : cellRowSpan === 1 ? rowHeight : 0;
                                    var verticalAlign = (cell.style ? cell.style['verticalAlign'] || 'Bottom' : 'Bottom').toLowerCase();
                                    if (!ej2_base_1.isNullOrUndefined(cell.image) && cell.image.length > 0) {
                                        this_1.processImages(i, j, cell, canvas, context, height, this_1.endRow, rowHeight, lineHeight, allowColumnAndRow, printOptions, sheet, printInstance, currentX, currentY, pageHeight, sheetIndex);
                                    }
                                    if (!ej2_base_1.isNullOrUndefined(cell.chart) && cell.chart.length > 0) {
                                        this_1.handleCharts(i, j, cell, context, canvas, height, this_1.endRow, this_1.initialRowCount, lineHeight, rowHeight, allowColumnAndRow, printOptions, sheet, printInstance, this_1.multipleCanvasDataURL, currentX, currentY, pageHeight, sheetIndex);
                                    }
                                    if (!ej2_base_1.isNullOrUndefined(cell.value) || !ej2_base_1.isNullOrUndefined(cell.formula) ||
                                        !ej2_base_1.isNullOrUndefined(cell.hyperlink)) {
                                        var position_1;
                                        if (cell.formula && cell.format) {
                                            this_1.parent.notify(index_2.workbookFormulaOperation, { action: 'refreshCalculate', rowIndex: j, colIndex: k,
                                                value: cell.formula, isFormula: index_2.checkIsFormula(cell.formula), sheetIndex: sheetIndex });
                                            var numberFormatArgs = {
                                                value: cell.value, format: cell.format,
                                                rowIndex: j, colIndex: k, sheetIndex: this_1.parent.activeSheetIndex,
                                                cell: cell, refresh: true
                                            };
                                            cellText_1 = this_1.parent.workbookNumberFormatModule.getFormattedCell(numberFormatArgs);
                                            position_1 = "" + (textAlign ? textAlign : numberFormatArgs.isRightAlign ? 'Right' : 'Left');
                                        }
                                        else if (cell.format) {
                                            var numberFormatArgs = {
                                                value: cell.value, format: cell.format,
                                                rowIndex: j, colIndex: k, sheetIndex: this_1.parent.activeSheetIndex,
                                                cell: cell, refresh: true
                                            };
                                            cellText_1 = this_1.parent.workbookNumberFormatModule.getFormattedCell(numberFormatArgs);
                                            position_1 = "" + (textAlign ? textAlign : numberFormatArgs.isRightAlign ? 'Right' : 'Left');
                                        }
                                        else if (cell.formula) {
                                            this_1.parent.notify(index_2.workbookFormulaOperation, { action: 'refreshCalculate', rowIndex: j, colIndex: k,
                                                value: cell.formula, isFormula: index_2.checkIsFormula(cell.formula), sheetIndex: sheetIndex });
                                            cellText_1 = cell.value;
                                            position_1 = "" + (textAlign ? textAlign : 'Left');
                                        }
                                        else {
                                            if (!ej2_base_1.isNullOrUndefined(cell.hyperlink)) {
                                                if (ej2_base_1.isNullOrUndefined(cell.value)) {
                                                    cell.value = (!ej2_base_1.isNullOrUndefined(cell.hyperlink) && typeof cell.hyperlink === 'object') ? cell.hyperlink['address'] : cell.hyperlink || cell.hyperlink['address'];
                                                }
                                                else Iif (ej2_base_1.isNullOrUndefined(cell.value) || cell.value === '') {
                                                    cell.value = typeof cell.hyperlink === 'object' ? cell.hyperlink['address'] : cell.hyperlink;
                                                }
                                                color_1 = cell.style ? cell.style.color || '#00e' : '#00e';
                                            }
                                            cellText_1 = cell.value;
                                            var isNumber = !ej2_base_1.isNullOrUndefined(cell.value) && cell.value !== '' ? new RegExp('^[^\\p{L}]*$', 'u').test(cell.value) : false;
                                            position_1 = '' + (textAlign ? textAlign : isNumber ? 'Right' : 'Left');
                                        }
                                        var textSize = (cell.style ? cell.style.fontSize || '11pt' : '11pt');
                                        var fontFamily = (cell.style ? cell.style.fontFamily || 'Calibri' : 'Calibri');
                                        var fontstyle = (cell.style ? cell.style.fontStyle || '' : '');
                                        var fontWeight = (cell.style ? cell.style.fontWeight || 'normal' : 'normal');
                                        context.font = fontstyle + " " + fontWeight + " " + textSize + " " + fontFamily;
                                        var textMetrics_1 = context.measureText(cellText_1);
                                        var textWidth_1 = textMetrics_1.width;
                                        var textHeight = textMetrics_1.actualBoundingBoxAscent + textMetrics_1.actualBoundingBoxDescent;
                                        if (cell.wrap) {
                                            var cellLineHeight_1 = this_1.defaultCellHeight < cellHeight ? ((parseInt(textSize.replace('pt', ''), 10) / 72) * 96) : cellHeight;
                                            var textLines = printInstance.wrapText(context, cellText_1, cellWidth_1);
                                            var space = (textLines.length === 1) ? cellHeight :
                                                (textLines.length * cellLineHeight_1 === cellHeight) ? cellLineHeight_1 :
                                                    (textLines.length * cellLineHeight_1 < cellHeight) ?
                                                        cellHeight - ((textLines.length - 1) * cellLineHeight_1) : cellLineHeight_1;
                                            var startY_1 = currentY[k] + (verticalAlign === 'top' ? cellLineHeight_1 : verticalAlign === 'middle' ?
                                                space > cellLineHeight_1 + (space / 4) ? cellLineHeight_1 + (space / 4) : space : space);
                                            context.save();
                                            context.beginPath();
                                            context.rect(currentX, currentY[k], cellWidth_1, cellHeight);
                                            context.clip();
                                            context.fillStyle = backgroundColor;
                                            context.fillRect(currentX, currentY[k], cellWidth_1, (cellHeight + (verticalAlign === 'top' ? cellLineHeight_1 : 0)));
                                            textLines.forEach(function (line, index) {
                                                context.fillStyle = color_1;
                                                textMetrics_1 = context.measureText(line);
                                                textWidth_1 = textMetrics_1.width;
                                                var locationX = printInstance.calculateTextPosition(textWidth_1, cellWidth_1, currentX, position_1);
                                                context.fillText(line, locationX, startY_1 + index * cellLineHeight_1);
                                                printInstance.textDecoration(cell, context, locationX, (startY_1 + index * cellLineHeight_1), color_1, textMetrics_1, cellText_1, cellWidth_1);
                                            });
                                            context.restore();
                                        }
                                        else {
                                            context.save();
                                            context.beginPath();
                                            context.rect(currentX, currentY[k], cellWidth_1, cellHeight);
                                            context.clip();
                                            context.fillStyle = backgroundColor;
                                            context.fillRect(currentX, currentY[k], cellWidth_1, cellHeight);
                                            context.fillStyle = color_1;
                                            var locationX = printInstance.calculateTextPosition(textWidth_1, cellWidth_1, currentX, position_1);
                                            var locationY = currentY[k] + (verticalAlign === 'top' ? textHeight + 2 :
                                                verticalAlign === 'middle' ? cellHeight > ((cellHeight / 2) + (textHeight / 2)) ?
                                                    ((cellHeight / 2) + (textHeight / 2)) : cellHeight : cellHeight);
                                            if (!ej2_base_1.isNullOrUndefined(cell.style)) {
                                                locationY = (!ej2_base_1.isNullOrUndefined(cell.style.borderBottom) && cell.style.borderBottom.indexOf('double') > -1) || (!ej2_base_1.isNullOrUndefined(cell.style.borderTop) && cell.style.borderTop.indexOf('double') > -1) ? locationY - 2 : locationY;
                                                locationX = (!ej2_base_1.isNullOrUndefined(cell.style.borderLeft) && cell.style.borderLeft.indexOf('double') > -1) || (!ej2_base_1.isNullOrUndefined(cell.style.borderRight) && cell.style.borderRight.indexOf('double') > -1) ? locationX + (position_1 === 'Left' ? 2 : -3) : locationX;
                                            }
                                            context.fillText(cellText_1, locationX, locationY);
                                            context.restore();
                                            printInstance.textDecoration(cell, context, locationX, locationY, color_1, textMetrics_1, cellText_1, cellWidth_1);
                                        }
                                    }
                                    else {
                                        printInstance.rowHeaderRect(context, currentX, currentY[k], cellWidth_1, cellHeight, backgroundColor);
                                    }
                                    if (cell.style && (cellWidth_1 > 0 || cellHeight > 0) && (cell.style.borderBottom || cell.style.borderTop
                                        || cell.style.borderLeft || cell.style.borderRight && ((ej2_base_1.isNullOrUndefined(cell.rowSpan) &&
                                        ej2_base_1.isNullOrUndefined(cell.colSpan)) || (!ej2_base_1.isNullOrUndefined(cell.rowSpan) && cell.rowSpan > 0) ||
                                        (!ej2_base_1.isNullOrUndefined(cell.colSpan) && cell.colSpan > 0)))) {
                                        printInstance.drawBorder(context, cell.style, currentX, (currentY[k] <= 0 ? 2 : currentY[k]), cellWidth_1, cellHeight);
                                    }
                                }
                                var currentWidth = (cellWidthSpan_1 <= 0 ? cellWidth_1 : (cellWidth_1 ||
                                    (sheet.columns[k] && sheet.columns[k].width) || this_1.defaultCellWidth));
                                if (printOptions.allowGridLines) {
                                    style.borderRight = k === end && allowColumnAndRow ? undefined : '1px solid black';
                                    printInstance.drawBorder(context, style, currentX, currentY[k], currentWidth, cellHeight);
                                }
                                currentX += currentWidth;
                                var currentYValue = 0;
                                if (cellRowSpan > 1) {
                                    currentYValue = currentY[k];
                                    for (var m = k; m < k + cellWidthSpan_1; m++) {
                                        var cell_1 = sheet.rows[j] && !ej2_base_1.isNullOrUndefined(sheet.rows[j].cells) &&
                                            sheet.rows[j].cells[m];
                                        if (cell_1 && !ej2_base_1.isNullOrUndefined(cell_1.image)) {
                                            this_1.processImages(i, j, cell_1, canvas, context, height, this_1.endRow, rowHeight, lineHeight, allowColumnAndRow, printOptions, sheet, printInstance, currentX, currentY, pageHeight, sheetIndex);
                                        }
                                        else Iif (cell_1 && !ej2_base_1.isNullOrUndefined(cell_1.chart)) {
                                            this_1.handleCharts(i, j, cell_1, context, canvas, height, this_1.endRow, this_1.initialRowCount, lineHeight, rowHeight, allowColumnAndRow, printOptions, sheet, printInstance, this_1.multipleCanvasDataURL, currentX, currentY, pageHeight, sheetIndex);
                                        }
                                        Iif (cell_1.style && m === k && cellHeight > 0 && (cell_1.style.borderBottom || cell_1.style.borderTop ||
                                            cell_1.style.borderLeft || cell_1.style.borderRight)) {
                                            printInstance.drawBorder(context, cell_1.style, currentX, currentY[k], 2, cellHeight);
                                        }
                                        currentY[m] = (isNaN(currentY[m]) ? defaultCellSpace :
                                            currentY[m]) + cellHeight;
                                    }
                                    k += cellWidthSpan_1 - 1;
                                }
                                if (k === end && allowColumnAndRow) {
                                    printInstance.drawBorder(context, rightStyle, currentX - 2, currentY[k] - currentYValue, 2, cellHeight);
                                }
                                if (k === end && allowColumnAndRow && borderOfHeaderText && !isExtraLine) {
                                    printInstance.drawBorder(context, bottomStyle, 0, currentY[k] - currentYValue, currentX, cellHeight);
                                    borderOfHeaderText = false;
                                }
                                if (cellRowSpan <= 1) {
                                    currentY[k] += cellHeight;
                                }
                            }
                            else if (allowColumnAndRow && k === start) {
                                var cellRowSpan = !ej2_base_1.isNullOrUndefined(cell) ?
                                    isNaN(sheet.rows[j].cells[k].rowSpan) ? 1 :
                                        Math.max(sheet.rows[j].cells[k].rowSpan, 0) : 1;
                                currentY[k] = (isNaN(currentY[k]) ? defaultCellSpace : currentY[k]);
                                var rowHeaderHeight = currentY[k];
                                context.font = '11pt Calibri';
                                for (var o = 0; o < cellRowSpan; o++) {
                                    currentX = 0;
                                    rowHeaderHeight += (o === 0 ? 0 : (sheet.rows[j + o] && sheet.rows[j + o - 1].height ||
                                        this_1.defaultCellHeight));
                                    printInstance.rowHeaderText((j + 1 + o).toString(), context, printInstance, headerWidth, currentX, style, rowHeaderHeight, sheet.rows[j + o].height || this_1.defaultCellHeight);
                                    currentX += headerWidth;
                                }
                                currentY[k] += cellHeight;
                            }
                            out_k_1 = k;
                        };
                        var this_1 = this, out_k_1;
                        for (var k = start; k <= end; k++) {
                            _loop_1(k);
                            k = out_k_1;
                        }
                    }
                    else Eif (isExtraLine || ej2_base_1.isNullOrUndefined(sheet.rows[j])) {
                        var style_1 = { borderBottom: '1px solid black', borderTop: '1px solid black', borderLeft: '1px solid black', borderRight: '1px solid black' };
                        borderOfHeaderText = ((height + cellHeight) + (j === 0 && allowColumnAndRow ?
                            this.defaultCellHeight : 0) > 1080) || (j === sheet.rows.length - 1) || (j === this.endRow - 1);
                        for (var k = start; k <= end; k++) {
                            var cell = sheet.rows[j] && !ej2_base_1.isNullOrUndefined(sheet.rows[j].cells) &&
                                sheet.rows[j].cells[k];
                            Iif (!ej2_base_1.isNullOrUndefined(cell) && !ej2_base_1.isNullOrUndefined(cell.style)) {
                                style_1 = this.setBorderStyle(cell, style_1);
                            }
                            if (allowColumnAndRow && k === start) {
                                printInstance.rowHeaderText((j + 1).toString(), context, printInstance, headerWidth, currentX, style_1, currentY[k], this.defaultCellHeight);
                                currentX += headerWidth;
                            }
                            var cellWidth = (sheet.columns[k] && sheet.columns[k].width || this.defaultCellWidth);
                            cellWidth = currentX + cellWidth > 1000 ? cellWidth - 1 - (currentX + cellWidth - 1000) : cellWidth;
                            currentY[k] = (isNaN(currentY[k]) ? defaultCellSpace : currentY[k]);
                            if (printOptions.allowGridLines) {
                                printInstance.drawBorder(context, style_1, currentX, currentY[k], cellWidth, cellHeight);
                            }
                            else if (allowColumnAndRow && !printOptions.allowGridLines && k === end) {
                                printInstance.drawBorder(context, { borderRight: '1px solid black' }, currentX, currentY[k], cellWidth, cellHeight);
                            }
                            currentX += cellWidth;
                            if (k === end && allowColumnAndRow && borderOfHeaderText) {
                                printInstance.drawBorder(context, bottomStyle, 0, currentY[k], currentX, cellHeight);
                                borderOfHeaderText = false;
                            }
                            currentY[k] += cellHeight;
                        }
                    }
                }
                if (!this.isImageLoaded && !this.isChartLoaded) {
                    if (isCanvasDataUrl && this.endRow > 0) {
                        this.multipleCanvasDataURL.push(canvas.toDataURL());
                    }
                    rowsCount = 0;
                    if (this.pageCounts.length - 1 === i) {
                        printInstance.canvasPrint(this.parent, sheetIndex, printOptions);
                    }
                }
                else Eif (this.isImageLoaded || this.isChartLoaded) {
                    break;
                }
            }
        };
        Print.prototype.setBorderStyle = function (cell, style) {
            style.borderBottom = !ej2_base_1.isNullOrUndefined(cell.style.borderBottom) ? cell.style.borderBottom : style.borderBottom;
            style.borderTop = !ej2_base_1.isNullOrUndefined(cell.style.borderTop) ? cell.style.borderTop : style.borderTop;
            style.borderRight = !ej2_base_1.isNullOrUndefined(cell.style.borderRight) ? cell.style.borderRight : style.borderRight;
            style.borderLeft = !ej2_base_1.isNullOrUndefined(cell.style.borderLeft) ? cell.style.borderLeft : style.borderLeft;
            return style;
        };
        Print.prototype.setToDefault = function () {
            this.parent.currentPrintSheetIndex = 0;
            this.initialRowCount = 0;
            this.chartHeight = 0;
            this.totalCharts = 0;
            this.totalImages = 0;
            this.chartLoadedCount = 0;
            this.imageLoadedCount = 0;
            this.endRow = 0;
            this.pageCounts = [];
            this.multipleCanvasDataURL = [];
            this.chartElements = [];
            this.isChartLoaded = false;
            this.isImageLoaded = false;
            this.startNewPageCount = 0;
        };
        Print.prototype.handleCharts = function (i, j, cell, context, canvas, height, rowCount, initialRowCount, lineHeight, rowHeight, allowColumnAndRow, printOptions, sheet, printInstance, multipleCanvasDataURL, currentX, currentY, pageHeight, sheetIndex) {
            var _this = this;
            Eif (!ej2_base_1.isNullOrUndefined(cell.chart)) {
                var _loop_2 = function (chart) {
                    this_2.totalCharts += 1;
                    var image = new Image();
                    chart.left = !ej2_base_1.isNullOrUndefined(chart.left) ? chart.left : 0;
                    chart.top = !ej2_base_1.isNullOrUndefined(chart.top) ? chart.top : 0;
                    var chartElement = document.getElementById(chart.id);
                    if (ej2_base_1.isNullOrUndefined(chartElement)) {
                        this_2.parent.insertChart([chart]);
                        chartElement = document.getElementById(chart.id);
                        this_2.chartElements.push(chart.id + '_overlay');
                    }
                    Eif (!ej2_base_1.isNullOrUndefined(chartElement)) {
                        this_2.chartHeight = chart.height;
                        var isExtraLine = (this_2.initialRowCount + Math.ceil(chart.height / 19) > this_2.endRow) &&
                            (printOptions.allowRowColumnHeader || printOptions.allowGridLines);
                        if (isExtraLine) {
                            Eif (sheet.rows.length - 1 === j) {
                                var extraSpace = rowHeight + (allowColumnAndRow ? this_2.defaultCellHeight : 0);
                                Iif (canvas.height > height + (this_2.chartHeight - extraSpace)) {
                                    this_2.endRow += Math.ceil((this_2.chartHeight - extraSpace) / 19);
                                }
                                else {
                                    this_2.endRow += Math.ceil((canvas.height - (height + extraSpace)) / 19);
                                }
                            }
                        }
                        var svgElement = chartElement.cloneNode(true);
                        var url = window.URL.createObjectURL(new Blob([(new XMLSerializer()).serializeToString(svgElement.childNodes[1])], { type: 'image/svg+xml' }));
                        image.onload = function () {
                            var chartLeftIndex = Math.ceil(chart.left / 1000) - 1;
                            var chartTopIndex = Math.ceil(chart.top / 1080) - 1;
                            var left = chart.left + (allowColumnAndRow ? 37 : 0);
                            var top = chart.top + (allowColumnAndRow ? 19 : 0) + (chartTopIndex > 0 ? lineHeight : 0);
                            context.drawImage(image, chartLeftIndex <= 0 ? left : left - (chartLeftIndex * 1000), chartTopIndex <= 0 ? top : top - (chartTopIndex * 1160), chart.width, chart.height);
                            _this.chartLoadedCount++;
                            if (_this.chartLoadedCount === _this.totalCharts) {
                                currentX += chart.width;
                                _this.isChartLoaded = false;
                                Eif (!_this.isImageLoaded) {
                                    multipleCanvasDataURL.push(canvas.toDataURL());
                                    var startValue = (_this.initialRowCount === sheet.rows.length - 1 && height < 1080) ?
                                        sheet.rows.length : _this.initialRowCount;
                                    var endValue = _this.endRow;
                                    _this.processCell(i, (startValue + 1 === endValue ? endValue : startValue), endValue, currentX, currentY, context, canvas, sheet, printInstance, pageHeight, height, false, sheetIndex, printOptions);
                                }
                            }
                        };
                        image.src = url;
                        this_2.isChartLoaded = true;
                    }
                };
                var this_2 = this;
                for (var _i = 0, _a = cell.chart; _i < _a.length; _i++) {
                    var chart = _a[_i];
                    _loop_2(chart);
                }
            }
        };
        Print.prototype.processImages = function (i, j, cell, canvas, context, height, rowCount, rowHeight, lineHeight, allowColumnAndRow, printOptions, sheet, printInstance, currentX, currentY, pageHeight, sheetIndex) {
            var _this = this;
            Eif (!ej2_base_1.isNullOrUndefined(cell.image)) {
                var _loop_3 = function (image) {
                    this_3.totalImages += 1;
                    var img = new Image();
                    img.src = image.src;
                    image.left = !ej2_base_1.isNullOrUndefined(image.left) ? image.left : 0;
                    image.top = !ej2_base_1.isNullOrUndefined(image.top) ? image.top : 0;
                    this_3.chartHeight = image.height;
                    var isExtraLine = (this_3.initialRowCount + Math.ceil(image.height / 19) > this_3.endRow) &&
                        (printOptions.allowRowColumnHeader || printOptions.allowGridLines);
                    if (isExtraLine) {
                        Iif (j === sheet.rows.length - 1) {
                            var extraSpace = (rowHeight + (allowColumnAndRow ? this_3.defaultCellHeight : 0));
                            if (canvas.height > (height + (this_3.chartHeight - extraSpace))) {
                                this_3.endRow += Math.ceil((this_3.chartHeight - extraSpace) / 19);
                            }
                            else {
                                this_3.endRow += Math.ceil((canvas.height - (height + extraSpace)) / 19);
                            }
                        }
                    }
                    img.onload = function () {
                        var imageLeftIndex = Math.ceil(image.left / 1000) - 1;
                        var imageTopIndex = Math.ceil(image.top / 1080) - 1;
                        var left = image.left + (allowColumnAndRow ? 37 : 0);
                        var top = image.top + (allowColumnAndRow ? 19 : 0) + (imageTopIndex > 0 ? lineHeight : 0);
                        context.drawImage(img, (imageLeftIndex <= 0 ? left : left - (imageLeftIndex * 1000)), (imageTopIndex <= 0 ? top : top - (imageTopIndex * 1160)), image.width, image.height);
                        _this.imageLoadedCount++;
                        if (_this.imageLoadedCount === _this.totalImages) {
                            _this.isImageLoaded = false;
                            currentX += image.width;
                            if (!_this.isChartLoaded) {
                                _this.multipleCanvasDataURL.push(canvas.toDataURL());
                                var startValue = (_this.initialRowCount === sheet.rows.length - 1 &&
                                    height < 1080) ? sheet.rows.length : _this.initialRowCount;
                                var endValue = _this.endRow;
                                _this.processCell(i, (startValue + 1 === endValue ? endValue : startValue), endValue, currentX, currentY, context, canvas, sheet, printInstance, pageHeight, height, false, sheetIndex, printOptions);
                            }
                        }
                    };
                    img.onerror = function () {
                        _this.imageLoadedCount++;
                        if (_this.imageLoadedCount === _this.totalImages) {
                            _this.isImageLoaded = false;
                            Eif (!_this.isChartLoaded) {
                                _this.multipleCanvasDataURL.push(canvas.toDataURL());
                                var startValue = (_this.initialRowCount === sheet.rows.length - 1 &&
                                    height < 1080) ? sheet.rows.length : _this.initialRowCount;
                                var endValue = _this.endRow;
                                _this.processCell(i, (startValue + 1 === endValue ? endValue : startValue), endValue, currentX, currentY, context, canvas, sheet, printInstance, pageHeight, height, false, sheetIndex, printOptions);
                            }
                        }
                    };
                };
                var this_3 = this;
                for (var _i = 0, _a = cell.image; _i < _a.length; _i++) {
                    var image = _a[_i];
                    _loop_3(image);
                }
                this.isImageLoaded = true;
            }
        };
        Print.prototype.textDecoration = function (cell, context, locationX, locationY, color, textMetrics, cellText, cellWidth) {
            if (cellText !== '' && (!ej2_base_1.isNullOrUndefined(cell.style) && !ej2_base_1.isNullOrUndefined(cell.style.textDecoration) &&
                cell.style.textDecoration.toLowerCase().indexOf('underline') > -1 || !ej2_base_1.isNullOrUndefined(cell.hyperlink))) {
                context.beginPath();
                context.moveTo(locationX, locationY - 3);
                context.lineTo(locationX + (textMetrics.width > cellWidth ? cellWidth :
                    textMetrics.width), locationY - 3);
                context.strokeStyle = color;
                context.lineWidth = 1;
                context.stroke();
            }
        };
        Print.prototype.rowHeaderRect = function (context, currentX, currentY, cellWidth, cellHeight, backgroundColor) {
            Iif (backgroundColor === void 0) { backgroundColor = '#ffffff'; }
            context.save();
            context.beginPath();
            context.rect(currentX, currentY, cellWidth, cellHeight);
            context.clip();
            context.fillStyle = backgroundColor;
            context.fillRect(currentX, currentY, cellWidth, cellHeight);
            context.restore();
        };
        Print.prototype.rowHeaderText = function (rowText, context, printInstance, headerWidth, currentX, style, currentY, height) {
            var textMetrics = context.measureText(rowText);
            var textWidth = textMetrics.width;
            var locationX = printInstance.calculateTextPosition(textWidth, headerWidth, currentX, 'Center');
            var locationY = currentY;
            context.save();
            context.beginPath();
            context.rect(currentX, currentY, headerWidth, height);
            context.clip();
            context.fillStyle = '#000000';
            context.fillText(rowText, locationX, (locationY + height));
            printInstance.drawBorder(context, style, currentX, (currentY || 0), headerWidth, height);
            context.restore();
        };
        Print.prototype.canvasPrint = function (spreadSheet, sheetIndex, printOptions) {
            var _this = this;
            if (printOptions.type === 'Workbook' && (this.totalSheetCount.length - 1) >= this.workbookActiveSheetCount) {
                var currentSheetIndex = this.totalSheetCount[this.workbookActiveSheetCount];
                var sheet = spreadSheet.sheets[currentSheetIndex];
                this.workbookActiveSheetCount++;
                this.activeSheetPrint(spreadSheet, sheet, printOptions, currentSheetIndex);
            }
            else {
                for (var i = 0; i < this.chartElements.length; i++) {
                    var chartElement = document.getElementById(this.chartElements[i]);
                    Eif (!ej2_base_1.isNullOrUndefined(chartElement)) {
                        chartElement.remove();
                    }
                }
                Eif (this.multipleCanvasDataURL.length > 0) {
                    var browserUserAgent = navigator.userAgent;
                    var printWindow_1 = window.open(' ', '_blank', 'height=' + window.outerHeight + ',width=' + window.outerWidth + ',tabbar=no');
                    printWindow_1.document.write('<html><head><title></title></head><body>');
                    var canvasWidth_1 = 1000;
                    var canvasHeight_1 = 1400;
                    Eif ((browserUserAgent.indexOf('Chrome') !== -1) || (browserUserAgent.indexOf('Safari') !== -1) ||
                        (browserUserAgent.indexOf('Firefox')) !== -1) {
                        printWindow_1.document.write('<!DOCTYPE html>');
                        printWindow_1.document.write('<html><head><style>html, body {  }'
                            + ' img { height: 100%; width: 100%; display: block; }@media print { body {  }'
                            + ' img { width:100%; width:100%; box-sizing: border-box; }br, button { display: none; }'
                            + ' div{ page-break-inside: avoid; }} @page{ size:' + canvasWidth_1.toString() + 'px ' + canvasHeight_1.toString() + 'px; }</style></head><body>');
                    }
                    else {
                        printWindow_1.document.write('<!DOCTYPE html>');
                        printWindow_1.document.write('<html><head>'
                            + '<style>html, body {  } img { height: 100%; width: 100%; }@media print { body {  }'
                            + 'img { width:100%; width:100%; box-sizing: border-box; }br, button { display: none; } '
                            + 'div{ page-break-inside: avoid; }} @page{ size:' + canvasWidth_1.toString() + 'px ' + canvasHeight_1.toString() + 'px; }</style></head><body>');
                    }
                    this.multipleCanvasDataURL.forEach(function (dataURL, index) {
                        var canvas = printWindow_1.document.createElement('canvas');
                        canvas.width = canvasWidth_1;
                        canvas.height = canvasHeight_1;
                        var context = canvas.getContext('2d');
                        var image = new Image();
                        image.onload = function () {
                            context.drawImage(image, 0, 0, canvasWidth_1, canvasHeight_1);
                            if (index === _this.multipleCanvasDataURL.length - 1) {
                                spreadSheet.isPrintingProcessing = false;
                                printWindow_1.print();
                                printWindow_1.document.close();
                                printWindow_1.close();
                                spreadSheet.printModule.setToDefault();
                            }
                        };
                        image.src = dataURL;
                        printWindow_1.document.body.appendChild(canvas);
                    });
                }
            }
        };
        Print.prototype.drawBorder = function (context, borderStyles, locationX, locationY, cellWidth, cellHeight) {
            var borderBottom = borderStyles.borderBottom, borderLeft = borderStyles.borderLeft, borderRight = borderStyles.borderRight, borderTop = borderStyles.borderTop, borderColor = borderStyles.borderColor;
            context.strokeStyle = borderColor || 'black';
            if (!ej2_base_1.isNullOrUndefined(borderBottom) && borderBottom.indexOf('#FFFFFF') === -1) {
                context.strokeStyle = borderBottom.split(' ')[2];
                this.drawPath(locationX, (locationY === 2 ? -2 : locationY) + cellHeight, locationX + cellWidth, (locationY === 2 ? -2 : locationY) + cellHeight, context, borderBottom, false, borderStyles, 'bottom');
            }
            if (!ej2_base_1.isNullOrUndefined(borderLeft) && borderLeft.indexOf('#FFFFFF') === -1) {
                context.strokeStyle = borderLeft.split(' ')[2];
                this.drawPath(locationX, locationY, locationX, (locationY === 2 ? -2 : locationY) + cellHeight, context, borderLeft, true, borderStyles, 'left');
            }
            if (!ej2_base_1.isNullOrUndefined(borderRight) && borderRight.indexOf('#FFFFFF') === -1) {
                context.strokeStyle = borderRight.split(' ')[2];
                this.drawPath(locationX + cellWidth, locationY, locationX + cellWidth, (locationY === 2 ? -2 : locationY) + cellHeight, context, borderRight, false, borderStyles, 'right');
            }
            if (!ej2_base_1.isNullOrUndefined(borderTop) && borderTop.indexOf('#FFFFFF') === -1) {
                context.strokeStyle = borderTop.split(' ')[2];
                this.drawPath(locationX, locationY, locationX + cellWidth, locationY, context, borderTop, true, borderStyles, 'top');
            }
        };
        Print.prototype.drawPath = function (startX, startY, endX, endY, context, border, isLeftOrTop, borderStyles, position) {
            context.beginPath();
            if (border.indexOf('dashed') > -1) {
                context.setLineDash([3, 2]);
                context.lineWidth = border.split(' ')[0].split('')[0];
            }
            else if (border.indexOf('dotted') > -1) {
                context.setLineDash([1, 1]);
                context.lineWidth = border.split(' ')[0].split('')[0];
            }
            else if (border.indexOf('double') > -1) {
                context.setLineDash([]);
                var isAllBorder = !ej2_base_1.isNullOrUndefined(borderStyles.borderBottom) && !ej2_base_1.isNullOrUndefined(borderStyles.borderLeft) &&
                    !ej2_base_1.isNullOrUndefined(borderStyles.borderRight) && !ej2_base_1.isNullOrUndefined(borderStyles.borderTop);
                var isLeftBottom = !ej2_base_1.isNullOrUndefined(borderStyles.borderBottom) && !ej2_base_1.isNullOrUndefined(borderStyles.borderLeft) &&
                    ej2_base_1.isNullOrUndefined(borderStyles.borderRight) && ej2_base_1.isNullOrUndefined(borderStyles.borderTop);
                var isLeftTop = ej2_base_1.isNullOrUndefined(borderStyles.borderBottom) && !ej2_base_1.isNullOrUndefined(borderStyles.borderLeft) &&
                    ej2_base_1.isNullOrUndefined(borderStyles.borderRight) && !ej2_base_1.isNullOrUndefined(borderStyles.borderTop);
                var isLeftTopBotom = !ej2_base_1.isNullOrUndefined(borderStyles.borderBottom) && !ej2_base_1.isNullOrUndefined(borderStyles.borderLeft) &&
                    ej2_base_1.isNullOrUndefined(borderStyles.borderRight) && !ej2_base_1.isNullOrUndefined(borderStyles.borderTop);
                var isRightBottom = !ej2_base_1.isNullOrUndefined(borderStyles.borderBottom) && ej2_base_1.isNullOrUndefined(borderStyles.borderLeft) &&
                    !ej2_base_1.isNullOrUndefined(borderStyles.borderRight) && ej2_base_1.isNullOrUndefined(borderStyles.borderTop);
                var isRightTop = ej2_base_1.isNullOrUndefined(borderStyles.borderBottom) && ej2_base_1.isNullOrUndefined(borderStyles.borderLeft) &&
                    !ej2_base_1.isNullOrUndefined(borderStyles.borderRight) && !ej2_base_1.isNullOrUndefined(borderStyles.borderTop);
                var isRightTopBottom = !ej2_base_1.isNullOrUndefined(borderStyles.borderBottom) && ej2_base_1.isNullOrUndefined(borderStyles.borderLeft) &&
                    !ej2_base_1.isNullOrUndefined(borderStyles.borderRight) && !ej2_base_1.isNullOrUndefined(borderStyles.borderTop);
                var isLeftTopRight = ej2_base_1.isNullOrUndefined(borderStyles.borderBottom) && !ej2_base_1.isNullOrUndefined(borderStyles.borderLeft) &&
                    !ej2_base_1.isNullOrUndefined(borderStyles.borderRight) && !ej2_base_1.isNullOrUndefined(borderStyles.borderTop);
                var isLeftBottomRight = !ej2_base_1.isNullOrUndefined(borderStyles.borderBottom) && !ej2_base_1.isNullOrUndefined(borderStyles.borderLeft)
                    && !ej2_base_1.isNullOrUndefined(borderStyles.borderRight) && ej2_base_1.isNullOrUndefined(borderStyles.borderTop);
                context.lineWidth = 1;
                var extraSpace = 3;
                if (isAllBorder) {
                    if (startX === endX) {
                        if (isLeftOrTop) {
                            this.drawDoubleBorder(context, startX, startY, endX, endY, startX + extraSpace, startY + extraSpace, endX + extraSpace, endY - (extraSpace - 1));
                        }
                        else {
                            this.drawDoubleBorder(context, startX, startY, endX, endY, startX - extraSpace, startY + extraSpace, endX - extraSpace, endY - (extraSpace - 1));
                        }
                    }
                    else Eif (startY === endY) {
                        if (isLeftOrTop) {
                            this.drawDoubleBorder(context, startX, startY, endX, endY, startX + (extraSpace - 1), startY + extraSpace, endX - (extraSpace - 1), endY + extraSpace);
                        }
                        else {
                            this.drawDoubleBorder(context, startX, startY, endX, endY, startX + (extraSpace - 1), startY - extraSpace, endX - (extraSpace - 1), endY - extraSpace);
                        }
                    }
                }
                else if (isLeftBottom) {
                    if (position === 'left') {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX + extraSpace, startY, endX + extraSpace, endY - (extraSpace - 1));
                    }
                    else {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX + (extraSpace - 1), startY - extraSpace, endX, endY - extraSpace);
                    }
                }
                else if (isLeftTop) {
                    if (position === 'left') {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX + extraSpace, startY + (extraSpace - 1), endX + extraSpace, endY);
                    }
                    else {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX + (extraSpace - 1), startY + extraSpace, endX, endY + extraSpace);
                    }
                }
                else if (isLeftTopBotom) {
                    if (position === 'left') {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX + extraSpace, startY + extraSpace, endX + extraSpace, endY - (extraSpace - 1));
                    }
                    else if (position === 'top') {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX + (extraSpace - 1), startY + extraSpace, endX, endY + extraSpace);
                    }
                    else {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX + (extraSpace - 1), startY - extraSpace, endX, endY - extraSpace);
                    }
                }
                else if (isRightBottom) {
                    if (position === 'right') {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX - extraSpace, startY, endX - extraSpace, endY - (extraSpace - 1));
                    }
                    else {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX, startY - extraSpace, endX - (extraSpace - 1), endY - extraSpace);
                    }
                }
                else if (isRightTop) {
                    if (position === 'right') {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX - extraSpace, startY + extraSpace, endX - extraSpace, endY);
                    }
                    else {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX, startY + extraSpace, endX - (extraSpace - 1), endY + extraSpace);
                    }
                }
                else if (isRightTopBottom) {
                    if (position === 'right') {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX - extraSpace, startY + extraSpace, endX - extraSpace, endY - (extraSpace - 1));
                    }
                    else if (position === 'top') {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX, startY + extraSpace, endX - (extraSpace - 1), endY + extraSpace);
                    }
                    else {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX, startY - extraSpace, endX - (extraSpace - 1), endY - extraSpace);
                    }
                }
                else if (isLeftTopRight) {
                    if (position === 'right') {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX - extraSpace, startY + extraSpace, endX - extraSpace, endY);
                    }
                    else if (position === 'top') {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX + extraSpace, startY + extraSpace, endX - (extraSpace - 1), endY + extraSpace);
                    }
                    else {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX + extraSpace, startY + extraSpace, endX + extraSpace, endY);
                    }
                }
                else Eif (isLeftBottomRight) {
                    if (position === 'right') {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX - extraSpace, startY, endX - extraSpace, endY - (extraSpace - 1));
                    }
                    else if (position === 'bottom') {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX + (extraSpace - 1), startY - extraSpace, endX - (extraSpace - 1), endY - extraSpace);
                    }
                    else {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX + extraSpace, startY, endX + extraSpace, endY - (extraSpace - 1));
                    }
                }
                else {
                    if (startX === endX) {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX + (position === 'left' ? extraSpace : -extraSpace), startY, endX + (position === 'left' ? extraSpace : -extraSpace), endY);
                    }
                    else if (startY === endY) {
                        this.drawDoubleBorder(context, startX, startY, endX, endY, startX, startY +
                            (position === 'top' ? extraSpace : -extraSpace), endX, endY + (position === 'top' ? extraSpace : -extraSpace));
                    }
                }
                context.stroke();
                return;
            }
            else {
                context.setLineDash([]);
                context.lineWidth = border.split(' ')[0].split('')[0];
            }
            context.moveTo(startX, startY);
            context.lineTo(endX, endY);
            context.stroke();
        };
        Print.prototype.drawDoubleBorder = function (context, startX1, startY1, endX1, endY1, startX2, startY2, endX2, endY2) {
            context.moveTo(startX1, startY1);
            context.lineTo(endX1, endY1);
            context.moveTo(startX2, startY2);
            context.lineTo(endX2, endY2);
        };
        Print.prototype.calculateTextPosition = function (textWidth, totalWidth, currentX, position) {
            var x;
            var space = 3;
            var availableSpace = totalWidth;
            if (availableSpace >= textWidth) {
                switch (position.toLowerCase()) {
                    case 'left':
                        x = currentX + space;
                        break;
                    case 'center':
                        x = currentX + (availableSpace - textWidth) / 2;
                        break;
                    case 'right':
                        x = currentX + availableSpace - textWidth;
                        break;
                }
            }
            else Iif (textWidth < totalWidth) {
                x = position.toLowerCase() === 'left' ? currentX + space : position.toLowerCase() === 'center' ? currentX + (totalWidth - textWidth) / 2
                    : currentX + totalWidth - textWidth;
            }
            else {
                x = currentX + space;
            }
            return x;
        };
        Print.prototype.calculatePageCount = function (sheet, columnHeaderWidth, allowColumnAndRow) {
            var allowHeader = allowColumnAndRow;
            var colIndex = this.columnIndex;
            if (sheet.columns.length === 0) {
                var columnCount = Math.floor(columnHeaderWidth / this.defaultCellWidth) - (allowHeader ? 1 : 0);
                return Array(Math.max(1, Math.ceil(colIndex / columnCount))).fill(columnCount);
            }
            var pageWidthCount = 0;
            var pageCount = [];
            for (var i = 0; i <= colIndex; i++) {
                var column = sheet.columns && sheet.columns[i];
                var columnWidth = (allowHeader ? 27 : 0) + ((column && column.hidden) ? 0 :
                    (column && !ej2_base_1.isNullOrUndefined(column.width)) ? column.width : this.defaultCellWidth);
                pageWidthCount += columnWidth;
                allowHeader = false;
                if (pageWidthCount > columnHeaderWidth) {
                    pageCount.push(i - 1);
                    allowHeader = true;
                    pageWidthCount = columnWidth;
                }
            }
            Eif (pageCount.length === 0 || colIndex > pageCount[pageCount.length - 1]) {
                pageCount.push(colIndex);
            }
            return pageCount;
        };
        Print.prototype.wrapText = function (context, text, maxWidth) {
            Iif (ej2_base_1.isNullOrUndefined(text)) {
                return [''];
            }
            text = typeof text === 'number' ? text + '' : text;
            var words = text.split(' ');
            var lines = [];
            var line = '';
            for (var i = 0; i < words.length; i++) {
                var testLine = line + words[i] + ' ';
                var metrics = context.measureText(testLine);
                var testWidth = metrics.width;
                if (testWidth > maxWidth && i > 0) {
                    lines.push(line);
                    line = words[i] + ' ';
                }
                else {
                    line = testLine;
                }
            }
            lines.push(line);
            return lines;
        };
        Print.prototype.getModuleName = function () {
            return 'print';
        };
        Print.prototype.destroy = function () {
            this.setToDefault();
            this.totalSheetCount = [];
            this.parent = null;
        };
        return Print;
    }());
    exports.Print = Print;
});