-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathdemo35.js
111 lines (96 loc) · 2.71 KB
/
demo35.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
107
108
109
110
/***
* This report tests using formatterFunctions with each print type
*/
"use strict";
const ReportBuilder = require('../lib/fluentReportsBuilder').ReportBuilder;
const displayReport = require('./reportDisplayer');
const data = [
{
"id": 1,
"name": "John Doe",
}
];
const reportData = {
"type": "report",
"dataUUID": 10002,
"version": 2,
"fontSize": 0,
"autoPrint": false,
"name": "demo35.pdf",
"paperSize": "letter",
"paperOrientation": "portrait",
"fonts": [],
"variables": {
"test": "12345"
},
"header": {
"children": [
{
"type": "raw",
"values": [
"Sample Header"
]
}
]
},
"detail": {
"children": [
{
"type": "print",
"settings": {
"formatFunction": "NumberFunction",
"absoluteX": 14,
"absoluteY": 1
},
"variable": "test"
},
{
"type": "print",
"settings": {
"formatFunction": "NumberFunction",
"absoluteX": 104,
"absoluteY": 1
},
"text": "1000"
},
{
"type": "print",
"settings": {
"formatFunction": "NumberFunction",
"absoluteX": 204,
"absoluteY": 1
},
"field": "id",
}
]
},
"footer": {
"children": [
{
"type": "raw",
"values": [
"Sample Footer"
]
}
]
}
};
reportData.formatterFunctions = {
'NumberFunction': function(input, data, callback) {
callback (input + '.00');
}
};
let rpt = new ReportBuilder(reportData, data);
// These two lines are not normally needed for any normal reports unless you want to use your own fonts...
// We need to add this because of TESTING and making the report consistent for CI environments
rpt.registerFont("Arimo", {normal: __dirname+'/Fonts/Arimo-Regular.ttf', bold: __dirname+'/Fonts/Arimo-Bold.ttf', 'italic': __dirname+'/Fonts/Arimo-Italic.ttf'})
.font("Arimo");
if (typeof process.env.TESTING === "undefined") { rpt.printStructure(); }
console.time("Rendered");
rpt.render().then((name) => {
console.timeEnd("Rendered");
const testing = {images: 1, blocks: ["120,130,300,100"]};
displayReport(null, name, testing);
}).catch((err) => {
console.error("Your report had errors while running", err);
});