-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (41 loc) · 1.22 KB
/
index.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
const pantherpdf = require('pantherpdf');
// API object is used to customize file storage and other backend services.
// It can be empty for basic usage.
const api = {};
// Build simple report and generate HTML.
async function main()
{
// Simple text field which will generate dynamic text.
const text = { type: 'TextSimple', value: { formula: '"Item " + item' }, children: [] };
// Repeat Text filed for each element of an array.
const repeat = {
type: 'Repeat',
children: [text],
source: { formula: 'data.listOfItems' },
varName: 'item',
direction: 'row',
};
const report = {
...pantherpdf.emptyReport,
widgets: [repeat],
};
// Root of source data. It's accessible using `data` variable.
const data = {
listOfItems: [ 'A', 'B', 'C', 'D' ],
};
// Wrapper to tell library what kind of data we want to use.
// In this case we supply JavaScript object exactly "as-is".
// Other options are:
// - URL to json or js file,
// - Javascript code as a string.
const dataWrapper = { type: 'as-is', value: data };
// Generate HTML
const result = await pantherpdf.generate({
report,
api,
data: dataWrapper,
});
// Print result.
console.log(result.html);
}
main();