-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_options.js
107 lines (74 loc) · 2.36 KB
/
pdf_options.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// not all! only those useful
// null -> will not be sent
const options = {
dpi: 96, // 72 better quality?
imageDpi: 600,
imageQuality: 94,
lowQuality: null,
marginBottom: null,
marginLeft: '10mm',
marginRight: '10mm',
marginTop: null,
orientation: 'Portrait',
pageSize: 'A4',
pageWidth: null,
pageHeight: null,
title: null,
outline: null, // enabled by default
noOutline: null, // not set by default
background: null, // default
noBackground: null,
cacheDir: null,
debugJavascript: null,
noDebugJavascript: null, // enabled by default
disableExternalLinks: null,
enableExternalLinks: null, // enabled by default
disableForms: null, // default
enableForms: null,
images: null, // default
noImages: null,
disableInternalLinks: null,
enableInternalLinks: null, // default
disableJavascript: null,
enableJavascript: null, // default
javascriptDelay: 200, // msec default
loadErrorHandling: null, // abort, ignore, or skip. Default: abort
loadMediaErrorHandling: null, // abort, ignore, or skip. Default: ignore
printMediaType: null,
noPrintMediaType: null, // default
proxy: null,
disableSmartShrinking: null,
enableSmartShrinking: null, // default
viewportSize: null,
zoom: 1,
};
function Options() {
this.options = options;
}
// copy of merge {default, custom}
Options.prototype.serialize = function (custom) {
let oThis = this;
let cloned = Object.assign({}, oThis.options);
if (typeof custom === 'object') {
Object.keys(custom).forEach(function (key) {
if (key in oThis.options) {
cloned[key] = custom[key];
}
});
}
Object.keys(cloned).forEach(function (key) {
// some items need to be excluded when sending through command line
// TODO: what if '0' is a valid value?
if (cloned[key] === null || cloned[key] === "" || cloned[key] === "false" || cloned[key] === '0') {
delete cloned[key];
}
// strict type! -> if true, will be included in command line but without value
if (cloned[key] === "true" || cloned[key] === '1') {
if (key !== 'zoom') {
cloned[key] = true;
}
}
});
return cloned;
};
module.exports = Options;