Repository navigation
Expand file tree
/
Copy pathprinter.js
More file actions
68 lines (58 loc) · 2.06 KB
/
Copy pathprinter.js
File metadata and controls
68 lines (58 loc) · 2.06 KB
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
const ipcRenderer = require('electron').ipcRenderer;
const moment = require('moment')
const { isInConfig } = require('./common')
const addHtmlToBody = (html) => {
let body = document.getElementById("page")
body.innerHTML = html
}
ipcRenderer.on('chargeHtml', (event, args) => {
if (args.css) {
addCStyles(args.css)
}
if (args.cssNode) {
addCStylesNode(args.cssNode)
}
if (args.cssUrl) {
addCStylesUrl(args.cssUrl)
}
addHtmlToBody(args.html)
if(args.sheetSize && ['A4','A3','A5'].includes(args.sheetSize)){
document.getElementsByTagName('body')[0].className = `${args.sheetSize} ${localStorage.getItem('landscape')}`
localStorage.setItem('PageType', args.sheetSize);
}else{
localStorage.setItem('PageType', 'A4');
}
if (isInConfig('timePrinter', args)) {
document.getElementById("timePrinter").style.display = ''
document.getElementById("timePrinter").innerHTML = moment.utc().format('YYYY-MM-DD HH:mm:ss');
}
if (isInConfig('hiddenWindow', args) || isInConfig('thermalprinter', args)) {
setTimeout(function(){ print( args,true ) }, 1000);
}
})
const transformScale = (scale) => {
document.getElementById("body").style.transform = `scale(${scale})`;
}
const addCStyles = (styles) => {
let css = document.createElement('style')
css.innerHTML = styles
document.getElementsByTagName("HEAD")[0].appendChild(css)
}
const addCStylesNode = (stylesNodde) => {
document.getElementsByTagName("HEAD")[0].appendChild(stylesNodde)
}
const addCStylesUrl = (stylesUrl) => {
var cssLink = document.createElement('link')
cssLink.setAttribute("rel", "stylesheet")
cssLink.setAttribute("type", "text/css")
cssLink.setAttribute("href", stylesUrl)
document.getElementsByTagName("HEAD")[0].appendChild(cssLink)
}
function print(args,close) {
args.close = close
ipcRenderer.send('print-init', args )
}
function printClick(close) {
ipcRenderer.send('print-init-click', { close })
}
module.exports = { transformScale, print , printClick}