-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
demo20.js
77 lines (53 loc) · 1.91 KB
/
demo20.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
"use strict";
// Test 20 - Opacity
// Test 20 - Report Pipes
const Report = require('../lib/fluentReports' ).Report;
const displayReport = require('./reportDisplayer');
function printreport() {
const mydata =
[
{
"group": 1,
"amount": 5
},
{
"group": 1,
"amount": 10
}
];
const groupfooter = function ( report, data, state ) {
// report.print("hi this is a test", {opacity: 0.5});
report.band([
["Totals for " + data.group, 180],
[report.totals.amount, 100, 3]
], {addY: 1, opacity: 0.4});
report.newLine();
};
// Example showing how to use report w/ PIPEs
const reportName = "demo20.pdf";
const fs = require('fs');
const pipe = fs.createWriteStream(reportName);
const rpt = new Report(pipe)//, {margins: {left:20, top:20, right: 20, bottom:20}})
.autoPrint(false) // Optional
.userdata( {hi: 1} )// Optional
.data( mydata ) // REQUIRED
.sum('amount');
// 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");
rpt.groupBy( "group" )
.sum('amount')
.footer( groupfooter );
// This does the MAGIC... :-)
console.time("Rendered");
rpt.render(function(err) {
console.timeEnd("Rendered");
const testing = {images: 1};
pipe.close();
displayReport(err, reportName, testing);
});
// Debug output is always nice (Optional, to help you see the structure)
if (typeof process.env.TESTING === "undefined") { rpt.printStructure(true); }
}
printreport();