This repository was archived by the owner on Aug 27, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathrender.js
More file actions
61 lines (51 loc) · 1.23 KB
/
Copy pathrender.js
File metadata and controls
61 lines (51 loc) · 1.23 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
const remote = require('../../util/remote')
const cst = require('./constants')
/**
* @param {object} info : info object
* - url
* - width
* - height
* @param {object} opts : component options
* @param {function} sendToMain
* - errorCode
* - result
* - imgData
*/
function render (info, opts = {}, sendToMain) {
let win = remote.createBrowserWindow({
width: info.width,
height: info.height,
show: !!opts.debug
})
const contents = win.webContents
const result = {}
let errorCode = null
const done = () => {
win.close()
if (errorCode) {
result.msg = cst.statusMsg[errorCode]
}
sendToMain(errorCode, result)
}
win.on('closed', () => {
win = null
})
// TODO
// - find better solution than IFRAME_LOAD_TIMEOUT
// - but really, we shouldn't be using iframes in embed view?
// - use `content.capturePage` to render PNGs and JPEGs
contents.once('did-finish-load', () => {
setTimeout(() => {
contents.printToPDF({}, (err, imgData) => {
if (err) {
errorCode = 525
return done()
}
result.imgData = imgData
return done()
})
}, cst.iframeLoadDelay)
})
win.loadURL(info.url)
}
module.exports = render