UNPKG

@syncfusion/ej2-pivotview

Version:

The pivot grid, or pivot table, is used to visualize large sets of relational data in a cross-tabular format, similar to an Excel pivot table.

721 lines (720 loc) 43.9 kB
import { PdfGrid, PdfPen, PointF, PdfDocument, PdfStandardFont, PdfFontFamily, PdfSolidBrush, PdfColor, PdfStringFormat, PdfVerticalAlignment, PdfTextAlignment, PdfFontStyle, PdfBorders, SizeF, PdfPageOrientation, PdfPaddings } from '@syncfusion/ej2-pdf-export'; import * as events from '../../common/base/constant'; import { isNullOrUndefined, initializeTelemetryFeature } from '@syncfusion/ej2-base'; import { PivotExportUtil } from '../../base/export-util'; import { PivotUtil } from '../../base/util'; import { PDFExportHelper } from './pdf-export-helper'; /** * @hidden * `PDFExport` module is used to handle the PDF export action. */ var PDFExport = /** @class */ (function () { /** * Constructor for the PivotGrid PDF Export module. * * @param {PivotView} parent - Instance of pivot table. * @hidden */ function PDFExport(parent) { this.createdDocuments = []; /** @hidden */ this.drawPosition = { xPosition: 0, yPosition: 0 }; initializeTelemetryFeature('pdfExport', 'pivotview'); this.parent = parent; this.pdfExportHelper = new PDFExportHelper(); } /** * For internal use only - Get the module name. * * @returns {string} - string. * @private */ PDFExport.prototype.getModuleName = function () { return 'pdfExport'; }; PDFExport.prototype.addPage = function (eventParams, pdfExportProperties) { if (this.createdDocuments.indexOf(eventParams.document) === -1) { this.createdDocuments.push(eventParams.document); } pdfExportProperties = pdfExportProperties ? pdfExportProperties : this.exportProperties.pdfExportProperties; var documentSection = eventParams.document.sections.add(); var documentHeight = eventParams.document.pageSettings.height; var documentWidth = eventParams.document.pageSettings.width; if (this.exportProperties.width || this.exportProperties.height) { eventParams.document.pageSettings.orientation = ((this.exportProperties.width > this.exportProperties.height) || (!this.exportProperties.height && (this.exportProperties.width > documentHeight)) || (!this.exportProperties.width && (documentWidth > this.exportProperties.height))) ? PdfPageOrientation.Landscape : PdfPageOrientation.Portrait; eventParams.document.pageSettings.size = new SizeF(this.exportProperties.width ? this.exportProperties.width : documentWidth, this.exportProperties.height ? this.exportProperties.height : documentHeight); } else { eventParams.document.pageSettings.orientation = (this.exportProperties.orientation === 0 || this.exportProperties.orientation) ? this.exportProperties.orientation : (!isNullOrUndefined(pdfExportProperties) && !isNullOrUndefined(pdfExportProperties.pageOrientation)) ? (pdfExportProperties.pageOrientation === 'Landscape' ? PdfPageOrientation.Landscape : PdfPageOrientation.Portrait) : PdfPageOrientation.Landscape; if (!isNullOrUndefined(pdfExportProperties) && !isNullOrUndefined(pdfExportProperties.pageSize)) { eventParams.document.pageSettings.size = PivotUtil.getPageSize(pdfExportProperties.pageSize); } } if (!isNullOrUndefined(this.exportProperties.pdfMargins)) { var margins = eventParams.document.pageSettings.margins; margins.top = !isNullOrUndefined(this.exportProperties.pdfMargins.top) ? this.exportProperties.pdfMargins.top : margins.top; margins.bottom = !isNullOrUndefined(this.exportProperties.pdfMargins.bottom) ? this.exportProperties.pdfMargins.bottom : margins.bottom; margins.left = !isNullOrUndefined(this.exportProperties.pdfMargins.left) ? this.exportProperties.pdfMargins.left : margins.left; margins.right = !isNullOrUndefined(this.exportProperties.pdfMargins.right) ? this.exportProperties.pdfMargins.right : margins.right; } documentSection.setPageSettings(eventParams.document.pageSettings); var page = documentSection.pages.add(); if (!isNullOrUndefined(pdfExportProperties) && !isNullOrUndefined(pdfExportProperties.header) && !isNullOrUndefined(this.pdfExportHelper)) { this.pdfExportHelper.drawHeader(pdfExportProperties, eventParams.document); } if (!isNullOrUndefined(pdfExportProperties) && !isNullOrUndefined(pdfExportProperties.footer) && !isNullOrUndefined(this.pdfExportHelper)) { this.pdfExportHelper.drawFooter(pdfExportProperties, eventParams.document); } return page; }; PDFExport.prototype.getFontStyle = function (theme) { var fontType = PdfFontStyle.Regular; if (!isNullOrUndefined(theme) && theme.bold) { fontType |= PdfFontStyle.Bold; } if (!isNullOrUndefined(theme) && theme.italic) { fontType |= PdfFontStyle.Italic; } if (!isNullOrUndefined(theme) && theme.underline) { fontType |= PdfFontStyle.Underline; } if (!isNullOrUndefined(theme) && theme.strikeout) { fontType |= PdfFontStyle.Strikeout; } return fontType; }; PDFExport.prototype.getBorderStyle = function (borderStyle) { var borders = new PdfBorders(); if (!isNullOrUndefined(borderStyle)) { var borderWidth = borderStyle.width; // set border width var width = (!isNullOrUndefined(borderWidth) && typeof borderWidth === 'number') ? borderWidth * 0.75 : undefined; // set border color var color = new PdfColor(196, 196, 196); if (!isNullOrUndefined(borderStyle.color)) { var borderColor = this.pdfExportHelper.hexDecToRgb(borderStyle.color); color = new PdfColor(borderColor.r, borderColor.g, borderColor.b); } var pen = new PdfPen(color, width); // set border dashStyle 'Solid <default>, Dash, Dot, DashDot, DashDotDot' if (!isNullOrUndefined(borderStyle.dashStyle)) { pen.dashStyle = this.pdfExportHelper.getDashStyle(borderStyle.dashStyle); } borders.all = pen; } else { var pdfColor = new PdfColor(234, 234, 234); borders.all = new PdfPen(pdfColor); } return borders; }; PDFExport.prototype.getStyle = function () { var header = (!isNullOrUndefined(this.gridStyle) && !isNullOrUndefined(this.gridStyle.header)) ? this.gridStyle.header : undefined; var fontFamily = (!isNullOrUndefined(header) && !isNullOrUndefined(header.fontName) && !isNullOrUndefined(this.pdfExportHelper)) ? this.pdfExportHelper.getFontFamily(header.fontName) : PdfFontFamily.Helvetica; var fontStyle = !isNullOrUndefined(header) ? this.getFontStyle(header) : this.getFontStyle(undefined); var fontSize = (!isNullOrUndefined(header) && !isNullOrUndefined(header.fontSize)) ? (header.fontSize * 0.80) : 11; var pdfColor = new PdfColor(); if (!isNullOrUndefined(header) && !isNullOrUndefined(header.fontColor)) { var rgb = this.pdfExportHelper.hexDecToRgb(header.fontColor); pdfColor = new PdfColor(rgb.r, rgb.g, rgb.b); } var font = new PdfStandardFont(fontFamily, fontSize, fontStyle); if (!isNullOrUndefined(header) && !isNullOrUndefined(header.font)) { font = header.font; } var border = !isNullOrUndefined(header) ? this.getBorderStyle(header.border) : this.getBorderStyle(undefined); return { border: border, font: font, brush: new PdfSolidBrush(pdfColor) }; }; PDFExport.prototype.setRecordThemeStyle = function (row) { var record = (!isNullOrUndefined(this.gridStyle) && !isNullOrUndefined(this.gridStyle.record)) ? this.gridStyle.record : undefined; var fontFamily = (!isNullOrUndefined(record) && !isNullOrUndefined(record.fontName) && !isNullOrUndefined(this.pdfExportHelper)) ? this.pdfExportHelper.getFontFamily(record.fontName) : PdfFontFamily.Helvetica; var fontSize = (!isNullOrUndefined(record) && !isNullOrUndefined(record.fontSize)) ? (record.fontSize * 0.80) : 11; var fontStyle = !isNullOrUndefined(record) ? this.getFontStyle(record) : this.getFontStyle(undefined); var font = new PdfStandardFont(fontFamily, fontSize, fontStyle); if (!isNullOrUndefined(record) && !isNullOrUndefined(record.font)) { font = record.font; } row.style.setFont(font); var pdfColor = new PdfColor(); if (!isNullOrUndefined(record) && !isNullOrUndefined(record.fontColor)) { var rgb = this.pdfExportHelper.hexDecToRgb(record.fontColor); pdfColor = new PdfColor(rgb.r, rgb.g, rgb.b); } row.style.setTextBrush(new PdfSolidBrush(pdfColor)); var borderRecord = (!isNullOrUndefined(record) && !isNullOrUndefined(record.border)) ? this.getBorderStyle(record.border) : this.getBorderStyle(undefined); row.style.setBorder(borderRecord); return row; }; /** * Method to perform pdf export. * * @param {PdfExportProperties} pdfExportProperties - Defines the export properties of the Grid. * @param {boolean} isMultipleExport - Define to enable multiple export. * @param {Object} pdfDoc - Defined the PDF document if multiple export is enabled. * @param {boolean} isBlob - If 'isBlob' set to true, then it will be returned as blob data. * @param {PivotView} currentPivotInstance - The current PivotView instance. * @returns {Promise<Object>} * @hidden */ PDFExport.prototype.exportToPDF = function (pdfExportProperties, isMultipleExport, pdfDoc, isBlob, currentPivotInstance) { var _this = this; var _a; this.parent = !isNullOrUndefined(currentPivotInstance) ? currentPivotInstance : this.parent; this.engine = this.parent.dataType === 'olap' ? this.parent.olapEngineModule : this.parent.engineModule; this.gridStyle = (!isNullOrUndefined(this.exportProperties) && !isNullOrUndefined(this.exportProperties.pdfExportProperties)) ? this.exportProperties.pdfExportProperties.theme : undefined; var eventParams = this.applyEvent(); var result; var appendPageDrawCount = 0; if (!isNullOrUndefined(pdfDoc)) { eventParams.document = pdfDoc['document']; } var headerStyle = this.getStyle(); var fileName = !isNullOrUndefined(this.exportProperties) && !isNullOrUndefined(this.exportProperties.fileName) ? this.exportProperties.fileName : (!isNullOrUndefined(pdfExportProperties) && !isNullOrUndefined(pdfExportProperties.fileName)) ? pdfExportProperties.fileName : 'default'; var indent = (this.parent.renderModule && this.parent.renderModule.maxIndent) || 5; var firstColumnWidth = 100 + (indent * 20); /** Fill data and export */ var dataCollIndex = 0; var pivotValues = eventParams.args.pivotValues[dataCollIndex]; var isEmptyPivotTable = PivotUtil.getPivotEmptyInfo(this.parent, this.engine); if (isEmptyPivotTable) { pivotValues = PivotUtil.getEmptyPivotValues(this.parent); } var pivotFirstRow = !isNullOrUndefined(pivotValues) && !isNullOrUndefined(pivotValues[0]) ? pivotValues[0] : undefined; var size = (!isNullOrUndefined(this.exportProperties) && this.exportProperties.columnSize > 0) ? this.exportProperties.columnSize : (!isNullOrUndefined(this.exportProperties) && !isNullOrUndefined(this.exportProperties.pdfExportProperties) && this.exportProperties.pdfExportProperties.allowHorizontalOverflow && !isNullOrUndefined(pivotFirstRow)) ? pivotFirstRow.length : (!isNullOrUndefined(pivotFirstRow) && pivotFirstRow.length > 5) ? 6 : !isNullOrUndefined(pivotFirstRow) ? pivotFirstRow.length : Math.floor((540 - firstColumnWidth) / 90) + 1; this.exportProperties.allowRepeatHeader = this.exportProperties.allowRepeatHeader === true || isNullOrUndefined(this.exportProperties.allowRepeatHeader); var allowRepeatHeader = this.exportProperties.allowRepeatHeader ? this.exportProperties.allowRepeatHeader : false; var isHeaderRepeatEligible = allowRepeatHeader && size > 1; var rowMaxLevel; if (this.parent.isTabular) { rowMaxLevel = this.parent.engineModule.rowMaxLevel; size = rowMaxLevel + 1 < size ? size : rowMaxLevel + 2; } for (var vLen = 0; isHeaderRepeatEligible && vLen < pivotValues.length; vLen++) { for (var vCnt = size; pivotValues[vLen] && vCnt < pivotValues[vLen].length; vCnt += size) { var rowHeaderLevel = this.parent.isTabular ? pivotValues[vLen].slice(0, rowMaxLevel + 1) : [pivotValues[vLen][0]]; (_a = pivotValues[vLen]).splice.apply(_a, [vCnt, 0].concat(rowHeaderLevel)); } } var colLength = pivotValues && pivotValues.length > 0 ? pivotValues[0].length : 0; var integratedCnt = 0; do { if (!isNullOrUndefined(pdfExportProperties)) { this.exportProperties.header = (!isNullOrUndefined(pdfExportProperties.header) && !isNullOrUndefined(pdfExportProperties.header.contents) && !isNullOrUndefined(pdfExportProperties.header.contents[0].value)) ? pdfExportProperties.header.contents[0].value : this.exportProperties.header; this.exportProperties.footer = (!isNullOrUndefined(pdfExportProperties.footer) && !isNullOrUndefined(pdfExportProperties.footer.contents) && !isNullOrUndefined(pdfExportProperties.footer.contents[0].value)) ? pdfExportProperties.footer.contents[0].value : this.exportProperties.footer; } var lastResult = (pdfDoc && pdfDoc['result']) ? pdfDoc['result'] : null; var page = (pdfDoc && pdfExportProperties && pdfExportProperties.multipleExport && pdfExportProperties.multipleExport.type === 'AppendToPage' && lastResult) ? lastResult.page : this.addPage(eventParams, pdfExportProperties); var pdfGrid = new PdfGrid(); var pageSize = size > 0 ? size : 5; if (pivotValues && pivotValues.length > 0) { pdfGrid.columns.add(pivotValues[0].length - integratedCnt >= pageSize ? pageSize : pivotValues[0].length - integratedCnt); var rowLen = pivotValues.length; var actualrCnt = 0; var maxLevel = 0; var columnWidth = 0; for (var rCnt = 0; rCnt < rowLen; rCnt++) { if (pivotValues[rCnt]) { var isColHeader = !(pivotValues[rCnt][0] && pivotValues[rCnt][0].axis === 'row'); var colLen = pivotValues[rCnt].length > (integratedCnt + pageSize) ? (integratedCnt + pageSize) : pivotValues[rCnt].length; var rowCount = 0; if (isColHeader) { pdfGrid.headers.add(1); } var pdfGridRow = !isColHeader ? pdfGrid.rows.addRow() : pdfGrid.headers.getHeader(actualrCnt); if (!isNullOrUndefined(pdfGridRow)) { pdfGridRow.height = (this.parent && this.parent.gridSettings) ? this.parent.gridSettings.rowHeight : pdfGridRow.height; } if (!isNullOrUndefined(pdfGrid.style)) { pdfGrid.style.cellPadding = new PdfPaddings(5.76, 5.76, 1.76, 1.76); } pdfGrid.repeatHeader = true; if (isColHeader) { pdfGridRow.style.setBorder(headerStyle.border); if (headerStyle.font) { pdfGridRow.style.setFont(headerStyle.font); } pdfGridRow.style.setTextBrush(headerStyle.brush); } else { this.setRecordThemeStyle(pdfGridRow); } var localCnt = 0; var isEmptyRow = true; for (var cCnt = integratedCnt; cCnt < colLen; cCnt++) { var isValueCell = false; var stringFormat = new PdfStringFormat(); stringFormat.lineAlignment = PdfVerticalAlignment.Middle; if (pivotValues[rCnt][cCnt]) { var pivotCell = pivotValues[rCnt][cCnt]; var isHeaderCollapsed = pivotCell.hasChild === true && pivotCell.isDrilled === false; var isSubTotalCell = pivotCell.type === 'sum' || pivotCell.type === 'grand sum'; var isRepeatLabelEnabled = this.parent.gridSettings.repeatItemLabels && !isHeaderCollapsed && !isSubTotalCell; if (pivotCell.rowSpan === 0 && isRepeatLabelEnabled) { pivotCell = Object.assign({}, pivotCell, { rowSpan: 1 }); } var cellValue = pivotCell.formattedText; var parentCell = void 0; if (pivotCell.rowSpan !== 0) { cellValue = (this.parent.dataSourceSettings.rows.length === 0 || this.parent.dataSourceSettings.columns.length === 0) ? this.parent.getValuesHeader(pivotCell, 'value') : cellValue; cellValue = pivotCell.type === 'grand sum' ? (this.parent.dataSourceSettings.rows.length === 0 || this.parent.dataSourceSettings.columns.length === 0) ? this.parent.getValuesHeader(pivotCell, 'grandTotal') : this.parent.localeObj.getConstant('grandTotal') : (pivotCell.type === 'sum' ? cellValue.toString().replace('Total', this.parent.localeObj.getConstant('total')) : cellValue); if (pivotCell.colSpan > 1) { parentCell = pdfGridRow.cells.getCell(localCnt); } if (!(pivotCell.level === -1 && !pivotCell.rowSpan)) { pdfGridRow.cells.getCell(localCnt).columnSpan = pivotCell.colSpan ? (pageSize - localCnt < pivotCell.colSpan ? pageSize - localCnt : pivotCell.colSpan) : 1; if ((isColHeader && pivotCell.rowSpan && pivotCell.rowSpan > 1) || (!isColHeader && pivotCell.rowSpan && pivotCell.rowSpan > 1 && this.parent.isTabular)) { pdfGridRow.cells.getCell(localCnt).rowSpan = isRepeatLabelEnabled ? 1 : (pivotCell.rowSpan ? pivotCell.rowSpan : 1); } else if (isRepeatLabelEnabled && pivotCell.rowSpan === 1) { pdfGridRow.cells.getCell(localCnt).rowSpan = 1; } pdfGridRow.cells.getCell(localCnt).value = cellValue ? cellValue.toString() : ''; if (cellValue !== '') { isEmptyRow = false; } } } maxLevel = pivotCell.level > maxLevel ? pivotCell.level : maxLevel; isValueCell = pivotCell.axis === 'value'; cCnt = cCnt + (pdfGridRow.cells.getCell(localCnt).columnSpan ? (pdfGridRow.cells.getCell(localCnt).columnSpan - 1) : 0); localCnt = localCnt + (pdfGridRow.cells.getCell(localCnt).columnSpan ? (pdfGridRow.cells.getCell(localCnt).columnSpan - 1) : 0); var isParentCellSpanned = !isNullOrUndefined(parentCell) && parentCell['colSpan'] > 1; var cell = isParentCellSpanned ? parentCell : pdfGridRow.cells.getCell(localCnt); var shouldApplyHeaderCellStyle = (pdfGridRow && pdfGridRow.isHeaderRow) || pivotCell.isGrandSum || pivotCell.type === 'grand sum' || pivotCell.axis === 'row'; if (shouldApplyHeaderCellStyle && !isNullOrUndefined(this.pdfExportHelper)) { this.pdfExportHelper.applyHeaderBackground(cell); } if (pivotCell.style) { pdfGridRow = this.applyStyle(pdfGridRow, pivotCell, localCnt); } stringFormat.alignment = isValueCell ? PdfTextAlignment.Right : PdfTextAlignment.Left; cell.style.stringFormat = stringFormat; var args = { style: undefined, pivotCell: pivotCell, cell: pdfGridRow.cells.getCell(localCnt), column: pdfGrid.columns.getColumn(localCnt) }; this.parent.trigger(events.onPdfCellRender, args); if (pivotCell.axis === 'column') { args = { style: args.style, cell: args.cell, gridCell: args.pivotCell, value: cellValue }; this.parent.trigger(events.pdfHeaderQueryCellInfo, args); cell.value = args.value ? args.value : cellValue; if (!isNullOrUndefined(this.pdfExportHelper)) { if (!isNullOrUndefined(args.image)) { this.pdfExportHelper.configureCellImage(cell, args.image, pdfGridRow); } this.pdfExportHelper.setHyperLink(cell, args, pdfGridRow, pivotCell, this.parent); } } else { args = { style: args.style, cell: args.cell, column: undefined, data: args.pivotCell, value: cellValue }; this.parent.trigger(events.pdfQueryCellInfo, args); cell.value = args.value ? args.value : cellValue; if (!isNullOrUndefined(this.pdfExportHelper)) { if (!isNullOrUndefined(args.image)) { this.pdfExportHelper.configureCellImage(cell, args.image, pdfGridRow); } this.pdfExportHelper.setHyperLink(cell, args, pdfGridRow, pivotCell, this.parent); } } if (args.style) { this.processCellStyle(cell, args); } } else { stringFormat.alignment = isValueCell ? PdfTextAlignment.Right : PdfTextAlignment.Left; var cell = pdfGridRow.cells.getCell(localCnt); cell.style.stringFormat = stringFormat; var args = { style: undefined, pivotCell: undefined, cell: cell, column: pdfGrid.columns.getColumn(localCnt) }; this.parent.trigger(events.onPdfCellRender, args); columnWidth = args.column.width; var pivotCell = { formattedText: '', colIndex: 0, rowIndex: rCnt }; args = { style: args.style, cell: args.cell, gridCell: pivotCell, value: undefined }; this.parent.trigger(events.pdfHeaderQueryCellInfo, args); cell.value = args.value ? args.value : ''; if (!isNullOrUndefined(this.pdfExportHelper)) { if (!isNullOrUndefined(args.image)) { this.pdfExportHelper.configureCellImage(cell, args.image, pdfGridRow); } if (pdfGridRow.isHeaderRow) { this.pdfExportHelper.applyHeaderBackground(cell); } this.pdfExportHelper.setHyperLink(cell, args, pdfGridRow, pivotCell, this.parent); } if (args.style) { this.processCellStyle(cell, args); } if (!isEmptyPivotTable) { if (this.parent.isTabular && rowCount === 0) { if (cCnt === 0 && isColHeader && this.parent.dataSourceSettings.columns && this.parent.dataSourceSettings.columns.length > 0) { pdfGrid.headers.getHeader(0).cells.getCell(0).rowSpan = Object.keys(this.engine.headerContent).length + 1; pdfGrid.headers.getHeader(0).cells.getCell(0).columnSpan = this.parent.engineModule.rowMaxLevel + 1; } else if (cCnt !== 0 && isColHeader && this.parent.dataSourceSettings.columns && this.parent.dataSourceSettings.columns.length > 0 && pdfGrid.headers.getHeader(0).cells.getCell(0).rowSpan < Object.keys(this.engine.headerContent).length) { pdfGrid.headers.getHeader(0).cells.getCell(0).rowSpan = Object.keys(this.engine.headerContent).length; pdfGrid.headers.getHeader(0).cells.getCell(0).columnSpan = this.parent.engineModule.rowMaxLevel + 1; } rowCount++; } else { if (cCnt === 0 && isColHeader && this.parent.dataSourceSettings.columns && this.parent.dataSourceSettings.columns.length > 0) { pdfGrid.headers.getHeader(0).cells.getCell(0).rowSpan++; } else if (cCnt !== 0 && isColHeader && this.parent.dataSourceSettings.columns && this.parent.dataSourceSettings.columns.length > 0 && pdfGrid.headers.getHeader(0).cells.getCell(0).rowSpan < Object.keys(this.engine.headerContent).length) { pdfGrid.headers.getHeader(0).cells.getCell(0).rowSpan++; } } } } if (this.parent.dataType === 'olap') { var indent_1 = 0; if (!isColHeader && localCnt === 0) { var cell = pivotValues[rCnt][cCnt]; if (cell) { var levelName = cell.valueSort.levelName.toString(); indent_1 = levelName.split(this.parent.dataSourceSettings.valueSortSettings.headerDelimiter).length - 1; } } stringFormat.paragraphIndent = indent_1 * 15; maxLevel = maxLevel > indent_1 ? maxLevel : indent_1; } else { stringFormat.paragraphIndent = 0; if ((!isColHeader && localCnt === 0 && pivotValues[rCnt][cCnt] && pivotValues[rCnt][cCnt].level !== -1)) { var cell = pivotValues[rCnt][cCnt]; var levelName = cell.valueSort ? cell.valueSort.levelName.toString() : ''; var memberPos = cell.actualText ? cell.actualText.toString().split(this.parent.dataSourceSettings.valueSortSettings.headerDelimiter) .length : 0; var levelPosition = levelName.split(this.parent.dataSourceSettings.valueSortSettings.headerDelimiter).length - (memberPos ? memberPos - 1 : memberPos); var level = levelPosition ? (levelPosition - 1) : 0; stringFormat.paragraphIndent = level * 10; } } localCnt++; } if (isEmptyRow) { pdfGridRow.height = 16; } actualrCnt++; } } pdfGrid.columns.getColumn(0).width = columnWidth > 0 ? columnWidth : 100 + (maxLevel * 20); } if (integratedCnt === 0 && this.parent.dataSourceSettings.columns && this.parent.dataSourceSettings.columns.length > 0 && !isEmptyPivotTable) { pdfGrid.headers.getHeader(0).cells.getCell(0).rowSpan--; } var xPosition = this.drawPosition['xPosition']; var yPosition = void 0; var isAppendToPage = !isNullOrUndefined(pdfDoc) && !isNullOrUndefined(pdfExportProperties) && !isNullOrUndefined(pdfExportProperties.multipleExport) && pdfExportProperties.multipleExport.type === 'AppendToPage' && !isNullOrUndefined(lastResult) && !isNullOrUndefined(lastResult.bounds); if (isAppendToPage) { var baseYPosition = lastResult.bounds.y + lastResult.bounds.height; yPosition = !isNullOrUndefined(pdfExportProperties.multipleExport.blankSpace) ? baseYPosition + pdfExportProperties.multipleExport.blankSpace : baseYPosition; var shouldAddNewPage = appendPageDrawCount > 0 || ((pdfGrid['gridHeaders'].rows[0].height + pdfGrid['gridHeaders'].count + yPosition) >= page.getClientSize().height); if (shouldAddNewPage) { page = this.addPage(eventParams, pdfExportProperties); yPosition = this.drawPosition['yPosition']; } } else { yPosition = this.drawPosition['yPosition']; } result = pdfGrid.draw(page, new PointF(xPosition, yPosition)); appendPageDrawCount++; integratedCnt = integratedCnt + pageSize; if (integratedCnt >= colLength && eventParams.args.pivotValues.length > (dataCollIndex + 1)) { dataCollIndex++; pivotValues = eventParams.args.pivotValues[dataCollIndex]; colLength = pivotValues && pivotValues.length > 0 ? pivotValues[0].length : 0; integratedCnt = 0; appendPageDrawCount = 0; } } while (integratedCnt < colLength); return new Promise(function (resolve) { var blobData; appendPageDrawCount = 0; if (isBlob || isMultipleExport) { if (isBlob) { blobData = eventParams.document.save(); } } else { eventParams.document.save(fileName + '.pdf'); eventParams.document.destroy(); } var exportCompleteEventArgs = { type: 'PDF', promise: isBlob ? blobData : null }; _this.parent.trigger(events.exportComplete, exportCompleteEventArgs); if (pdfExportProperties && pdfExportProperties.multipleExport && pdfExportProperties.multipleExport.type === 'AppendToPage') { resolve({ document: eventParams.document, result: result }); } else { resolve(eventParams.document); } }); }; PDFExport.prototype.applyStyle = function (pdfGridRow, pivotCell, localCnt) { var color = this.parent.conditionalFormattingModule.hexToRgb(pivotCell.style.backgroundColor); var brush = new PdfSolidBrush(new PdfColor(color.r, color.g, color.b)); pdfGridRow.cells.getCell(localCnt).style.backgroundBrush = brush; var size = Number(pivotCell.style.fontSize.split('px')[0]); var font = new PdfStandardFont(PdfFontFamily.TimesRoman, size, PdfFontStyle.Regular); pdfGridRow.cells.getCell(localCnt).style.font = font; color = this.parent.conditionalFormattingModule.hexToRgb(pivotCell.style.color); brush = new PdfSolidBrush(new PdfColor(color.r, color.g, color.b)); pdfGridRow.cells.getCell(localCnt).style.textBrush = brush; return pdfGridRow; }; PDFExport.prototype.getFont = function (theme) { if (theme.style.font) { return theme.style.font; } var fontSize = !isNullOrUndefined(theme.style.fontSize) ? (theme.style.fontSize * 0.80) : (theme.cell['cellStyle'].font && theme.cell['cellStyle'].font.fontSize) ? theme.cell['cellStyle'].font.fontSize : 11; var fontFamily = (!isNullOrUndefined(theme.style.fontFamily) && !isNullOrUndefined(this.pdfExportHelper)) ? (this.pdfExportHelper.getFontFamily(theme.style.fontFamily)) : PdfFontFamily.TimesRoman; var fontStyle = PdfFontStyle.Regular; if (!isNullOrUndefined(theme.style.bold) && theme.style.bold) { fontStyle |= PdfFontStyle.Bold; } if (!isNullOrUndefined(theme.style.italic) && theme.style.italic) { fontStyle |= PdfFontStyle.Italic; } if (!isNullOrUndefined(theme.style.underline) && theme.style.underline) { fontStyle |= PdfFontStyle.Underline; } if (!isNullOrUndefined(theme.style.strikeout) && theme.style.strikeout) { fontStyle |= PdfFontStyle.Strikeout; } return new PdfStandardFont(fontFamily, fontSize, fontStyle); }; PDFExport.prototype.processCellStyle = function (gridCell, arg) { if (!isNullOrUndefined(arg.style.backgroundColor)) { var backColor = this.pdfExportHelper.hexDecToRgb(arg.style.backgroundColor); gridCell.style.backgroundBrush = new PdfSolidBrush(new PdfColor(backColor.r, backColor.g, backColor.b)); } if (!isNullOrUndefined(arg.style.textBrushColor)) { var textBrushColor = this.pdfExportHelper.hexDecToRgb(arg.style.textBrushColor); gridCell.style.textBrush = new PdfSolidBrush(new PdfColor(textBrushColor.r, textBrushColor.g, textBrushColor.b)); } if (!isNullOrUndefined(arg.style.textPenColor)) { var textColor = this.pdfExportHelper.hexDecToRgb(arg.style.textPenColor); gridCell.style.textPen = new PdfPen(new PdfColor(textColor.r, textColor.g, textColor.b)); } if (!isNullOrUndefined(arg.style.fontFamily) || !isNullOrUndefined(arg.style.fontSize) || !isNullOrUndefined(arg.style.bold) || !isNullOrUndefined(arg.style.italic) || !isNullOrUndefined(arg.style.underline) || !isNullOrUndefined(arg.style.strikeout)) { gridCell.style.font = this.getFont(arg); } if (!isNullOrUndefined(arg.style.border)) { var border = new PdfBorders(); var borderWidth = arg.style.border.width; // set border width var width = (!isNullOrUndefined(borderWidth) && typeof borderWidth === 'number') ? (borderWidth * 0.75) : (undefined); // set border color var color = new PdfColor(196, 196, 196); if (!isNullOrUndefined(arg.style.border.color)) { var borderColor = this.pdfExportHelper.hexDecToRgb(arg.style.border.color); color = new PdfColor(borderColor.r, borderColor.g, borderColor.b); } var pen = new PdfPen(color, width); // set border dashStyle 'Solid <default>, Dash, Dot, DashDot, DashDotDot' if (!isNullOrUndefined(arg.style.border.dashStyle)) { pen.dashStyle = this.pdfExportHelper.getDashStyle(arg.style.border.dashStyle); } border.all = pen; gridCell.style.borders = border; } if (!isNullOrUndefined(arg.style) && !isNullOrUndefined(arg.style.textAlignment) && !isNullOrUndefined(gridCell.style) && !isNullOrUndefined(gridCell.style.stringFormat)) { gridCell.style.stringFormat.alignment = arg.style.textAlignment === 'Right' ? PdfTextAlignment.Right : PdfTextAlignment.Left; } if (!isNullOrUndefined(arg.style) && !isNullOrUndefined(arg.style.verticalAlignment) && !isNullOrUndefined(gridCell.style) && !isNullOrUndefined(gridCell.style.stringFormat)) { gridCell.style.stringFormat.lineAlignment = arg.style.verticalAlignment === 'Top' ? PdfVerticalAlignment.Top : arg.style.verticalAlignment === 'Bottom' ? PdfVerticalAlignment.Bottom : PdfVerticalAlignment.Middle; } }; PDFExport.prototype.applyEvent = function () { /** Event trigerring */ var clonedValues; var mdxQuery; var currentPivotValues = PivotExportUtil.getClonedPivotValues(this.engine.pivotValues); if (this.parent.exportAllPages && (this.parent.enableVirtualization || this.parent.enablePaging) && this.parent.dataSourceSettings.mode !== 'Server') { var pageSettings = this.engine.pageSettings; this.engine.isPagingOrVirtualizationEnabled = false; if (this.parent.dataType === 'olap') { this.updateOlapPageSettings(true); mdxQuery = this.parent.olapEngineModule.mdxQuery.slice(0); } else { this.engine.pageSettings = null; } this.engine.generateGridData(this.parent.dataSourceSettings, true, true); this.parent.applyFormatting(this.engine.pivotValues); clonedValues = PivotExportUtil.getClonedPivotValues(this.engine.pivotValues); this.engine.pivotValues = currentPivotValues; this.engine.pageSettings = pageSettings; this.engine.isPagingOrVirtualizationEnabled = true; if (this.parent.dataType === 'olap') { this.updateOlapPageSettings(false); this.parent.olapEngineModule.mdxQuery = mdxQuery; } } else { clonedValues = currentPivotValues; } var args = { pivotValues: [clonedValues] }; this.parent.trigger(events.enginePopulated, args); this.document = new PdfDocument(); return { document: this.document, args: args }; }; PDFExport.prototype.updateOlapPageSettings = function (isUpdate) { this.parent.olapEngineModule.isExporting = isUpdate ? true : false; if (!this.parent.exportSpecifiedPages) { this.parent.olapEngineModule.pageSettings = isUpdate ? null : this.parent.olapEngineModule.pageSettings; this.parent.olapEngineModule.isPaging = isUpdate ? false : true; } else { this.parent.olapEngineModule.exportSpeciedPages = this.parent.exportSpecifiedPages = isUpdate ? this.parent.exportSpecifiedPages : undefined; } }; PDFExport.prototype.cleanupDocument = function (document) { if (document) { document.destroy(); var index = this.createdDocuments.indexOf(document); if (index !== -1) { this.createdDocuments.splice(index, 1); } } }; /** * To destroy the pdf export module. * * @returns {void} * @hidden */ PDFExport.prototype.destroy = function () { for (var i = 0; i < this.createdDocuments.length; i++) { this.cleanupDocument(this.createdDocuments[i]); } this.createdDocuments = []; if (this.document) { this.cleanupDocument(this.document); this.document = null; } if (this.pdfExportHelper) { this.pdfExportHelper = null; } if (this.engine) { this.engine = null; } if (this.exportProperties) { this.exportProperties = null; } if (this.gridStyle) { this.gridStyle = null; } }; return PDFExport; }()); export { PDFExport };