-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader-footer-example.js
More file actions
112 lines (107 loc) · 2.91 KB
/
Copy pathheader-footer-example.js
File metadata and controls
112 lines (107 loc) · 2.91 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
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
107
108
109
110
111
112
const fs = require('fs');
const { Container, Page, RepeatVertical, StackVertical, Text } = require('../src/components/index.js');
const { PageSize, TextAlignment, Alignment } = require('../src/components/enums/index.js');
const { Offset, Border, BorderSide } = require('../src/components/models/index.js');
const ReplyPDF = require('../src/reply-pdf.js');
module.exports = {
generate: () => {
const template = new Page({
size: PageSize.A4,
margin: new Offset({
left: 50,
top: 50,
right: 50,
bottom: 50,
}),
firstPageHeader: new Container({
height: 150,
backgroundColor: '#fcc',
border: new Border(),
children: [
new StackVertical({
margin: new Offset(10),
children: [
new Text({
text: 'Sample PDF document - Header & Footer - {{date}}',
}),
new Text({
text: 'First Page Header',
}),
],
}),
],
}),
header: new Container({
height: 50,
backgroundColor: '#cfc',
border: new Border(),
children: [
new StackVertical({
margin: new Offset(10),
children: [
new Text({
text: 'Sample PDF document - Header & Footer - {{date}}',
}),
new Text({
text: 'Normal Page Header',
}),
],
}),
],
}),
footer: new Container({
height: 50,
children: [
new Text({
horizontalAlignment: Alignment.start,
verticalAlignment: Alignment.end,
fontSize: 10,
text: '{{date}}',
}),
new Text({
horizontalAlignment: Alignment.end,
verticalAlignment: Alignment.end,
fontSize: 10,
textAlignment: TextAlignment.right,
text: 'Page {{pageNumber}} of {{pageCount}}',
}),
],
}),
children: [
new RepeatVertical({
binding: 'arrayValues',
template: new Container({
margin: new Offset({
top: 5,
}),
border: new Border(),
children: [
new Text({
margin: new Offset(5),
text: 'Array value: {{.}}',
}),
],
}),
}),
],
});
const array = [];
for (let i = 0; i < 100; i++) {
array.push(i);
}
const data = {
arrayValues: array,
date: (new Date()).toLocaleDateString(),
};
let doc = ReplyPDF.generateDocument({
info: {
title: 'Header & Footer Sample PDF',
},
data: data,
template: template,
debug: false,
});
doc.pipe(fs.createWriteStream('examples/outputs/output-header-footer-example.pdf'));
doc.end();
}
}