UNPKG

unserver-unify

Version:

60 lines (59 loc) 1.61 kB
'use strict'; angular.module('bamboo.common').service('printHelper', printHelper); printHelper.$inject = []; function printHelper() { var self = this; /** * @param {any} text * @return */ self.printText = function(text) { var w = window.open(); w.document.write(text); w.print(); w.close(); } self.printPage = function() { window.print(); } /** * downloadFileByURL * @param {string} fileUrl * @return */ self.downloadFileByURL = function(fileUrl) { var pom = document.createElement('a'); pom.setAttribute('href', fileUrl); pom.setAttribute('download', ''); if (document.createEvent) { var event = document.createEvent('MouseEvents'); event.initEvent('click', true, true); pom.dispatchEvent(event); } else { pom.click(); } }; /** * save div as PDF * @param {string} id - div id * @param {string} filename - download file name * @return * dependency : html2canvas and pdfMake */ /* self.savePageAsPdfById = function(id, filename) { html2canvas(document.getElementById(id), { onrendered: function(canvas) { var data = canvas.toDataURL(); var docDefinition = { content: [{ image: data, width: 500, }] }; pdfMake.createPdf(docDefinition).download(filename); } }); } */ }