/
page_paper_size.partial
49 lines (37 loc) · 1.81 KB
/
page_paper_size.partial
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
{% if input.getType() == 'pdf' %}
var paperWidth = '{{ input.getPaperWidth() }}',
paperHeight = '{{ input.getPaperHeight() }}',
paperFormat = '{{ input.getFormat() }}',
paperOrientation = '{{ input.getOrientation() }}',
paperMargin = {{ input.getMargin()|json_encode(constant('JSON_FORCE_OBJECT')) }},
header = {{ input.getRepeatingHeader()|json_encode(constant('JSON_FORCE_OBJECT')) }},
footer = {{ input.getRepeatingFooter()|json_encode(constant('JSON_FORCE_OBJECT')) }};
if(paperWidth && paperHeight) {
debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Set page size ~ width: ' + paperWidth + ' height: ' + paperHeight + ' margin: ' + paperMargin);
var paperSize = {
width: paperWidth,
height: paperHeight,
margin: paperMargin
};
} else {
debug.push(new Date().toISOString().slice(0, -5) + ' [INFO] PhantomJS - Set page size ~ format: ' + paperFormat + ' orientation: ' + paperOrientation + ' margin: ' + paperMargin);
var paperSize = {
format: paperFormat,
orientation: paperOrientation,
margin: paperMargin
};
}
paperSize.header = {
height: header.height,
contents: phantom.callback(function(pageNum, pageTotal) {
return header.content.replace('%pageNum%', pageNum).replace('%pageTotal%', pageTotal);
})
};
paperSize.footer = {
height: footer.height,
contents: phantom.callback(function(pageNum, pageTotal) {
return footer.content.replace('%pageNum%', pageNum).replace('%pageTotal%', pageTotal);
})
};
page.paperSize = paperSize;
{% endif %}