Print.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /*
  4. *+------------------------------------------------------------------------+
  5. *| Licensed Materials - Property of IBM
  6. *| IBM Cognos Products: Content Explorer
  7. *| (C) Copyright IBM Corp. 2019
  8. *|
  9. *| US Government Users Restricted Rights - Use, duplication or disclosure
  10. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  11. *+------------------------------------------------------------------------+
  12. */
  13. define(['doT', 'jquery', '../../../../../app/nls/StringResources', '../../../../../lib/@waca/core-client/js/core-client/utils/BrowserUtils', '../../../../../lib/@waca/core-client/js/core-client/utils/ClassFactory', 'text!../../../../../dashboard/views/templates/FilterPDFContainer.html', '../../../../../lib/@waca/dashboard-common/dist/ui/interaction/Utils', '../../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../PrintAPI'], function (doT, $, StringResources, BrowserUtils, ClassFactory, FilterTemplate, CommonUiUtils, APIFactory, PrintAPI) {
  14. var Print = function () {
  15. //These sizes specify the viewport for the various browser print sizes.
  16. function Print(options) {
  17. _classCallCheck(this, Print);
  18. this._dashboard = options.features.API;
  19. this.pdfSizes = {
  20. Chrome: {
  21. Letter: { height: 520, width: 710 },
  22. Legal: { height: 520, width: 930 },
  23. A4: { height: 500, width: 770 },
  24. Tabloid: { height: 700, width: 1150 }
  25. },
  26. Firefox: {
  27. Letter: { height: 510, width: 670 },
  28. Legal: { height: 510, width: 880 },
  29. A4: { height: 470, width: 720 },
  30. Tabloid: { height: 660, width: 1100 }
  31. },
  32. IE: {
  33. Letter: { height: 480, width: 660 },
  34. Legal: { height: 480, width: 810 },
  35. A4: { height: 460, width: 680 },
  36. Tabloid: { height: 620, width: 980 }
  37. },
  38. Other: {
  39. Letter: { height: 450, width: 620 },
  40. Legal: { height: 450, width: 820 },
  41. A4: { height: 440, width: 670 },
  42. Tabloid: { height: 620, width: 1030 }
  43. }
  44. };
  45. this.orientation = 'portrait';
  46. this.pageSize = 'letter';
  47. this.GeneratePDFView = {};
  48. this.toast = {};
  49. this.layoutController = {};
  50. this.tabsHidden = false;
  51. this.contents = {};
  52. }
  53. Print.prototype.getAPI = function getAPI() {
  54. return APIFactory.createAPI(this, [PrintAPI]);
  55. };
  56. Print.prototype.registerContent = function registerContent(type, api) {
  57. this.contents[type] = api;
  58. };
  59. Print.prototype.isItemVisible = function isItemVisible() {
  60. return true;
  61. };
  62. Print.prototype.print = function print(id, context, pageOptions) {
  63. /*global requirejs: true*/
  64. var pdfSize = this._getPageSize(pageOptions.pageSize);
  65. var oldTimeout = requirejs.s.contexts._.config.waitSeconds;
  66. this.context = context;
  67. var contentType = this._dashboard.getCanvas().getContent(id).getType();
  68. this.subAPI = this.contents[contentType];
  69. requirejs.config({
  70. waitSeconds: 900 // 15 mins to be safe
  71. });
  72. var layoutController = this._dashboard.getCurrentContentView().boardController.layoutController;
  73. this.tabsHidden = layoutController.boardModel.layout.get('hideTab');
  74. var pageElement = context.glassContext.appController.currentAppView.getCurrentContentView().$el;
  75. return this._renderDashboard(layoutController, pageElement, pdfSize, pageOptions.printFilters).finally(function () {
  76. requirejs.config({
  77. waitSeconds: oldTimeout
  78. });
  79. });
  80. };
  81. Print.prototype._getPageSize = function _getPageSize(pageSize) {
  82. //Each Browser has a slightly different viewport when printing hence the different page sizes
  83. var pdfSize = {};
  84. if (BrowserUtils.isFirefox()) {
  85. pdfSize = { height: this.pdfSizes.Firefox[pageSize.pageSize].height, width: this.pdfSizes.Firefox[pageSize.pageSize].width };
  86. } else if (BrowserUtils.isChrome()) {
  87. pdfSize = { height: this.pdfSizes.Chrome[pageSize.pageSize].height, width: this.pdfSizes.Chrome[pageSize.pageSize].width };
  88. } else if (BrowserUtils.isIE()) {
  89. pdfSize = { height: this.pdfSizes.IE[pageSize.pageSize].height, width: this.pdfSizes.IE[pageSize.pageSize].width };
  90. } else {
  91. pdfSize = { height: this.pdfSizes.Other[pageSize.pageSize].height, width: this.pdfSizes.Other[pageSize.pageSize].width };
  92. }
  93. this.orientation = pageSize.orientation;
  94. this.pageSize = pageSize.pageSize;
  95. this.orientation = this.orientation.toLowerCase();
  96. this.pageSize = this.pageSize.toLowerCase();
  97. if (this.orientation === 'portrait') {
  98. var height = pdfSize.height;
  99. var width = pdfSize.width;
  100. pdfSize.width = height;
  101. pdfSize.height = width;
  102. }
  103. // This is needed for safari since the footer is printed on the outside of the margin.
  104. if (BrowserUtils.isSafari()) {
  105. pdfSize.width = pdfSize.width + 50;
  106. }
  107. return pdfSize;
  108. };
  109. Print.prototype._renderDashboard = function _renderDashboard(layoutController, pageElement, pdfSize, printFilters) {
  110. var layout = layoutController.boardModel.layout;
  111. var models = layout.items;
  112. var modelIds = models.map(function (model) {
  113. return model.id;
  114. });
  115. this._showToast();
  116. var content = {
  117. modelIds: modelIds,
  118. layoutType: layout.type,
  119. pageElement: pageElement[0],
  120. context: this.context,
  121. printPageSize: pdfSize
  122. };
  123. return this.subAPI.showContentsForPrint(content).then(function () {
  124. return this.tabRenderer(models, layoutController).then(function () {
  125. var widgetIds = [];
  126. $.each($(pageElement).find('.widget'), function (i, widget) {
  127. widgetIds.push($(widget).attr('id'));
  128. });
  129. return this.whenWidgetsRendered(widgetIds, layoutController);
  130. }.bind(this));
  131. }.bind(this)).then(function () {
  132. var mapWidgetIds = [];
  133. $.each($(pageElement).find('.widget'), function (i, widget) {
  134. if ($(widget).has('.TiledMapBundleRenderer').length > 0) {
  135. mapWidgetIds.push($(widget).attr('id'));
  136. }
  137. }.bind(this));
  138. return this.renderMapsForPrint(layoutController, mapWidgetIds);
  139. }.bind(this)).delay(this._getDelay(pageElement)) //Timeout is needed for the VIDA map animation.
  140. .then(function () {
  141. var tabTitles = [];
  142. models.forEach(function (model) {
  143. tabTitles.push(model.title);
  144. });
  145. var dashboardSizes = [];
  146. if (pageElement.find('.pageTabContent').length) {
  147. $.each(pageElement.find('.pageTabContent'), function (i, tab) {
  148. dashboardSizes.push(this._getDashboardSizes(tab));
  149. }.bind(this));
  150. } else if (pageElement.find('.pagecontainer').length) {
  151. $.each(pageElement.find('.pagecontainer'), function (i, tab) {
  152. dashboardSizes.push(this._getDashboardSizes(tab));
  153. }.bind(this));
  154. } else if (pageElement.find('.pageabsolute').length) {
  155. $.each(pageElement.find('.pageabsolute'), function (i, tab) {
  156. dashboardSizes.push(this._getDashboardSizes(tab));
  157. }.bind(this));
  158. }
  159. if (printFilters) {
  160. var filters = this.getFilters(layoutController, models);
  161. this.scaleDashboard(dashboardSizes, tabTitles, pdfSize, filters);
  162. } else {
  163. this.scaleDashboard(dashboardSizes, tabTitles, pdfSize);
  164. }
  165. return this.toast.remove(0);
  166. }.bind(this)).delay(1000) // delaying so Toast can disappear and not show up in pdf
  167. .then(function () {
  168. if (!this.isCancelled) {
  169. window.print();
  170. }
  171. }.bind(this)).catch(function () {
  172. if (!this.isCancelled) {
  173. this.isCancelled = true;
  174. layoutController.glassContext.appController.showToast(StringResources.get('errorPDF'), {
  175. type: 'error',
  176. preventDuplicates: true
  177. });
  178. }
  179. }.bind(this)).finally(function () {
  180. return this.subAPI.hideContentsAfterPrint(modelIds, pageElement[0]).then(function () {
  181. // Remove all the added styles
  182. this._removeAllPdfStyles();
  183. this.isCancelled = false;
  184. this.toast.remove(0);
  185. }.bind(this));
  186. }.bind(this));
  187. };
  188. Print.prototype._getDashboardSizes = function _getDashboardSizes(tab) {
  189. var pageSize = this.findPageSize(tab);
  190. var offSceenPageSize = this.subAPI.getOffScreenPageSize(tab);
  191. var dashboardSize = offSceenPageSize && this._dashboard.getCanvas().findContent().length > 0 ? offSceenPageSize : pageSize;
  192. var childrenId = !tab.id.indexOf($(tab).children().first().attr('id')) ? $(tab).children().first().attr('id') : $(tab).children().first().next().attr('id');
  193. return { 'size': dashboardSize, 'id': $(tab).attr('id'), childId: childrenId, absolute: this._checkIfPageAbsolute(tab) };
  194. };
  195. Print.prototype._getDelay = function _getDelay(pageElement) {
  196. var delay = 2000;
  197. if (BrowserUtils.isIE()) {
  198. delay = 7000;
  199. }
  200. if ($(pageElement).find('.TiledMapBundleRenderer').length > 0) {
  201. delay = 10000;
  202. }
  203. return delay;
  204. };
  205. Print.prototype._showToast = function _showToast() {
  206. var _this = this;
  207. ClassFactory.loadModule('dashboard-core/js/lib/@waca/core-client/js/core-client/ui/ProgressToast').then(function (ProgressToast) {
  208. _this.toast = new ProgressToast({ noHideBtn: true });
  209. _this.toast.show(StringResources.get('buildingPDF'));
  210. _this.toast.indefinite(StringResources.get('buildingPDF'));
  211. _this.toast.onCancel(function () {
  212. _this.isCancelled = true;
  213. });
  214. });
  215. };
  216. Print.prototype.getFilters = function getFilters(layoutController, models) {
  217. var widgets = layoutController.boardModel.widgetInstances;
  218. var pageFilters = [];
  219. $.each(models, function (i, model) {
  220. var tabWidgets = [];
  221. $.each(widgets, function (i, widget) {
  222. if (widget.type === 'live') {
  223. var idArray = [];
  224. idArray.push(model.id);
  225. var widgetsOnTab = model.listWidgets(idArray);
  226. if (this._checkIfWidgetInModel(widgetsOnTab, widget)) {
  227. var widgetLayout = layoutController.getLayoutView(widget.id);
  228. var widgetFilters = widgetLayout.widgetAPI.getWidgetLocalFilters();
  229. widgetFilters = widgetFilters.concat(widgetLayout.widgetAPI.getWidgetGlobalFilters());
  230. widgetFilters = widgetFilters.concat(widgetLayout.widgetAPI.getWidgetTopBottom());
  231. if (widgetFilters.length > 0) {
  232. tabWidgets.push({ 'id': widget.id, 'filters': widgetFilters });
  233. }
  234. }
  235. }
  236. }.bind(this));
  237. pageFilters.push({ 'id': model.id, widgets: tabWidgets });
  238. }.bind(this));
  239. return pageFilters;
  240. };
  241. Print.prototype._checkIfWidgetInModel = function _checkIfWidgetInModel(items, widget) {
  242. var match = false;
  243. $.each(items, function (i, item) {
  244. if (item === widget.id) {
  245. match = true;
  246. }
  247. }.bind(this));
  248. return match;
  249. };
  250. Print.prototype.createFilterContainer = function createFilterContainer(filters, pdfSize) {
  251. var html = doT.template(FilterTemplate)({
  252. widgets: filters.widgets,
  253. widgetText: StringResources.get('pdfWidget'),
  254. filterTitle: StringResources.get('filtersPresentPDF'),
  255. height: pdfSize.height
  256. });
  257. return html;
  258. };
  259. Print.prototype.numberWidgets = function numberWidgets(dashboard, widgets) {
  260. $.each(widgets, function (i, widget) {
  261. var widgetElement = $('#' + dashboard.id).find('#' + widget.id);
  262. var widgetNumber = i + 1;
  263. widgetElement.append('<div class="widgetPDFNumber">' + widgetNumber + '</div>');
  264. });
  265. };
  266. Print.prototype.renderMapsForPrint = function renderMapsForPrint(layoutController, widgetIds) {
  267. return Promise.map(widgetIds, function (widgetId) {
  268. if (this.isCancelled) {
  269. return Promise.reject();
  270. }
  271. var mapWidget = layoutController.widgetLoader.getWidget(widgetId);
  272. return mapWidget.mapVizRenderForPrint();
  273. }.bind(this));
  274. };
  275. Print.prototype.tabRenderer = function tabRenderer(models, layoutController) {
  276. return Promise.map(models, function (model) {
  277. if (this.isCancelled) {
  278. return Promise.reject();
  279. }
  280. return layoutController.getLayoutViewWhenReady(model.id).then(function (layoutView) {
  281. layoutView.onShow();
  282. });
  283. }.bind(this));
  284. };
  285. Print.prototype.whenWidgetsRendered = function whenWidgetsRendered(widgetIds, layoutController) {
  286. var widgetPromises = Promise.map(widgetIds, function (id) {
  287. if (this.isCancelled) {
  288. return Promise.reject();
  289. }
  290. var widgetLoader = this._dashboard.getDashboardCoreSvc('widgetLoader');
  291. var feature = widgetLoader.getWidget(id);
  292. feature && feature.resize();
  293. if (feature) {
  294. return feature.whenRenderComplete();
  295. }
  296. return layoutController.whenWidgetRenderComplete(id);
  297. }.bind(this));
  298. return Promise.all(widgetPromises);
  299. };
  300. Print.prototype._removeAllPdfStyles = function _removeAllPdfStyles() {
  301. $('.dashboardPdf').remove();
  302. $('.widgetPdf').remove();
  303. $('.widgetPDFNumber').remove();
  304. $('.pdfFilterList').remove();
  305. };
  306. Print.prototype._fixWidgetsStyle = function _fixWidgetsStyle(pageElement, className) {
  307. var widgetStyleOverride = '';
  308. $.each($(pageElement).find(className), function (i, widget) {
  309. var widgetId = $(widget).attr('id');
  310. var LabelContentLocation = widgetId + ' .vis-container [data-area=row] [data-node=content]';
  311. var _$$css = $(widget).css(['width', 'height', 'top', 'left']),
  312. width = _$$css.width,
  313. height = _$$css.height,
  314. top = _$$css.top,
  315. left = _$$css.left;
  316. var visContainerNodeContent = $(widget).find('.vis-container [data-area=row] [data-node=content]');
  317. var labelMargin = visContainerNodeContent && visContainerNodeContent.css(['margin-right']);
  318. var labelMarginInt = labelMargin && Math.abs(parseInt(labelMargin['margin-right']));
  319. if (!$(widget).parent().hasClass('pagegroup')) {
  320. widgetStyleOverride = widgetStyleOverride + ' #' + widgetId + '{ width:' + width + ' !important; height:' + height + ' !important; top: ' + top + ' !important; left: ' + left + ' !important; position: fixed !important;}';
  321. } else {
  322. widgetStyleOverride = widgetStyleOverride + ' #' + widgetId + '{ position: absolute !important; top: ' + top + ' !important; left: ' + left + ' !important;}';
  323. }
  324. widgetStyleOverride = visContainerNodeContent && widgetStyleOverride + ' #' + LabelContentLocation + '{ margin-right: ' + labelMarginInt + 'px !important; }' || widgetStyleOverride;
  325. });
  326. return widgetStyleOverride;
  327. };
  328. Print.prototype._fixWidgets = function _fixWidgets(pageElement) {
  329. var widgetStyleOverride = this._fixWidgetsStyle(pageElement, '.widget') + this._fixWidgetsStyle(pageElement, '.page.pagegroup');
  330. $('head').append('<style class="widgetPdf" rel="stylesheet" type="text/css" media="print"> @media print {' + widgetStyleOverride + '}</style>');
  331. };
  332. // This is for IE. IE doesn't respect the parent transform so I scale the widgets directly.
  333. Print.prototype._scaleWidgets = function _scaleWidgets(pageElement, scale) {
  334. var widgetString = '';
  335. var topPosition = 0;
  336. var leftPosition = 0;
  337. var scaleZero = 'matrix3d(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)';
  338. $.each($(pageElement).find('.widget'), function (i, widget) {
  339. var turnAngle = CommonUiUtils.getAngleDegree(widget);
  340. var _$$css2 = $(widget).css(['width', 'height', 'top', 'left']),
  341. width = _$$css2.width,
  342. height = _$$css2.height,
  343. top = _$$css2.top,
  344. left = _$$css2.left;
  345. topPosition = parseFloat(top) * scale;
  346. leftPosition = parseFloat(left) * scale;
  347. if (!$(widget).parent().hasClass('pagegroup') && $(widget).css('transform') !== scaleZero) {
  348. widgetString = widgetString + ' #' + $(widget).attr('id') + '{ width:' + width + ' !important; height:' + height + ' !important; top: ' + topPosition + 'px !important; left: ' + leftPosition + 'px !important; transform:scale(' + scale + ') rotate(' + turnAngle + 'deg) !important; transform-origin: top left !important;}';
  349. } else {
  350. widgetString = widgetString + ' #' + $(widget).attr('id') + '{ position: absolute !important}';
  351. }
  352. }.bind(this));
  353. $.each($(pageElement).find('.page.pagegroup'), function (i, widget) {
  354. var turnAngle = CommonUiUtils.getAngleDegree(widget);
  355. var _$$css3 = $(widget).css(['width', 'height', 'top', 'left']),
  356. width = _$$css3.width,
  357. height = _$$css3.height,
  358. top = _$$css3.top,
  359. left = _$$css3.left;
  360. topPosition = parseFloat(top) * scale;
  361. leftPosition = parseFloat(left) * scale;
  362. if (!$(widget).parent().hasClass('pagegroup')) {
  363. widgetString = widgetString + ' #' + $(widget).attr('id') + '{ width:' + width + ' !important; height:' + height + ' !important; top: ' + topPosition + 'px !important; left: ' + leftPosition + 'px !important; transform-origin: top left !important; transform:scale(' + scale + ') rotate(' + turnAngle + 'deg) !important; position: absolute !important;}';
  364. } else {
  365. widgetString = widgetString + ' #' + $(widget).attr('id') + '{ position: absolute !important}';
  366. }
  367. }.bind(this));
  368. $('head').append('<style class="widgetPdf" rel="stylesheet" type="text/css" media="print"> @media print {' + widgetString + '}</style>');
  369. };
  370. Print.prototype.findPageSize = function findPageSize(pageElement) {
  371. var pagecontainer = pageElement.querySelector('.pagecontainer');
  372. var pageSize = {
  373. height: $(pagecontainer).height(),
  374. width: $(pagecontainer).width()
  375. };
  376. return pageSize;
  377. };
  378. Print.prototype._checkIfPageAbsolute = function _checkIfPageAbsolute(pageElement) {
  379. if ($(pageElement).find('.pageabsolute').length) {
  380. return true;
  381. }
  382. return false;
  383. };
  384. Print.prototype.scaleDashboard = function scaleDashboard(dashboardSizes, tabTitles, pdfSize, filters) {
  385. var scale = 0;
  386. $.each(dashboardSizes, function (i, dashboard) {
  387. scale = this.scalePageSizes(pdfSize, dashboard);
  388. var $dashboard = $('#' + dashboard.id);
  389. if (BrowserUtils.isIE() || $dashboard.hasClass('pagecontainer') || $dashboard.hasClass('pageabsolute')) {
  390. this._scaleWidgets($('#' + dashboard.id), scale);
  391. } else {
  392. this._fixWidgets($('#' + dashboard.id));
  393. }
  394. if (tabTitles) {
  395. this.appendPrintStyles(scale, dashboard, tabTitles[i], pdfSize);
  396. } else {
  397. this.appendPrintStyles(scale, dashboard, tabTitles, pdfSize);
  398. }
  399. if (filters && filters[i].widgets.length > 0) {
  400. var element = this.createFilterContainer(filters[i], pdfSize);
  401. $('#' + dashboard.id).after(element);
  402. this.numberWidgets(dashboard, filters[i].widgets);
  403. }
  404. }.bind(this));
  405. return;
  406. };
  407. Print.prototype.appendPrintStyles = function appendPrintStyles(scale, dashboard, tabTitle, pdfSize) {
  408. var elementString = '';
  409. if (scale > 1) {
  410. if (tabTitle && !this.tabsHidden) {
  411. if (tabTitle.toString().indexOf('\\') !== -1) {
  412. tabTitle = tabTitle.toString().replace(/\\/g, '\\\\');
  413. }
  414. if (tabTitle.toString().indexOf('"') !== -1) {
  415. tabTitle = tabTitle.toString().replace(/"/g, '\\"');
  416. }
  417. elementString = elementString + '#' + dashboard.id + '::before{content:"' + tabTitle + '"; display: block; display: block; margin-left: -12px; margin-top: -2px; padding-left: 12px; width:' + $('#page1_tab').width() + 'px; background: white;} #' + dashboard.id + '{ width: ' + pdfSize.width + 'pt; height: ' + pdfSize.height + 'pt;}';
  418. }
  419. elementString = elementString + ' #' + dashboard.id + '{ width: ' + pdfSize.width + 'pt; height: ' + pdfSize.height + 'pt;}';
  420. elementString = elementString + ' #' + dashboard.id + '{ page-break-after: always !important; page-break-inside: avoid !important;-webkit-column-break-inside: avoid !important; break-inside: avoid !important; display: flex !important; flex-direction: column;\
  421. vertical-align: top !important;}';
  422. } else {
  423. if (tabTitle && !this.tabsHidden) {
  424. elementString = elementString + '#' + dashboard.id + '::before{content:"' + tabTitle + '"; display: block; margin-left: -12px; margin-top:-2px; padding-left: 12px; width:' + $('#page1_tab').width() + 'px; background: white;}';
  425. }
  426. elementString = elementString + ' #' + dashboard.id + '{ width: ' + pdfSize.width + 'pt; height: ' + pdfSize.height + 'pt;}';
  427. if (BrowserUtils.isIE()) {
  428. elementString = elementString + ' #' + dashboard.id + '{ page-break-after: always !important; -webkit-column-break-inside: avoid !important; break-inside: avoid !important; page-break-inside: avoid; display: flex !important; flex-direction: column; vertical-align: top !important; overflow: visible !important;} #' + dashboard.childId + '{display: block !important; position:relative !important z-index:10; visibility: visible; overflow: visible !important;}';
  429. } else {
  430. elementString = elementString + ' #' + dashboard.id + '{ page-break-after: always !important; -webkit-column-break-inside: avoid !important; break-inside: avoid !important; page-break-inside: avoid; display: flex !important; flex-direction: column; vertical-align: top !important; overflow: visible !important;} #' + dashboard.childId + '{width: ' + dashboard.size.width + 'px; height: ' + dashboard.size.height + 'px; transform:scale(' + scale + ') !important; transform-origin: 0 0 !important; display: block !important; position:relative !important; z-index:10; visibility: visible; overflow: visible !important;}';
  431. }
  432. }
  433. $('head').append('<style class="dashboardPdf" rel="stylesheet" type="text/css" media="print"> @media print { @page { size: ' + this.pageSize + ' ' + this.orientation + ';}' + elementString + ' } </style>');
  434. };
  435. Print.prototype.scalePageSizes = function scalePageSizes(pdfSize, dashboard) {
  436. var scale = 0;
  437. var scaleX = 0;
  438. var scaleY = 0;
  439. //Factor to convert px to pts, eg:1 px = .75 pt
  440. var dashboardScale = 0.75;
  441. //Width and height in pt
  442. var boardWidth = dashboard.size.width * dashboardScale;
  443. var boardHeight = dashboard.size.height * dashboardScale;
  444. scaleX = pdfSize.width / boardWidth;
  445. scaleY = pdfSize.height / boardHeight;
  446. if (scaleX < scaleY) {
  447. scale = scaleX;
  448. } else {
  449. scale = scaleY;
  450. }
  451. return scale;
  452. };
  453. return Print;
  454. }();
  455. return Print;
  456. });
  457. //# sourceMappingURL=Print.js.map