-
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathdemo03.js
More file actions
137 lines (105 loc) · 4.22 KB
/
Copy pathdemo03.js
File metadata and controls
137 lines (105 loc) · 4.22 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var Report = require('../lib/fluentReports' ).Report;
var fs = require('fs');
var displayReport = require('./reportDisplayer');
function printreport(options) {
'use strict';
options = options || {};
var Current_Date = new Date().toDateString();
var header = function(rpt, data) {
// Confidential text, we need this first because everything else prints on top of it
rpt.print('Confidential', {x: 40, y: 610, rotate: 310, opacity: 0.5, textColor: '#eeeeee', width: 1000, fontSize: 127});
// Company Info - Top Left
rpt.setCurrentY(14);
if (options.image && fs.existsSync(options.image)) {
rpt.image(options.image, {width: 200});
}
rpt.setCurrentY(rpt.getCurrentY() - 10);
if (options.address) { rpt.print(options.address, {x: 44}); }
if (options.address2) { rpt.print(options.address2, {x: 44}); }
if (options.city && options.state && options.postal) {
rpt.print(options.city + ', ' + options.state + ' ' + options.postal, {x: 44});
}
// Print our nice Fax header
rpt.print('FAX', {x: 420, y: 40, fontSize: 80});
rpt.fontSize(13);
rpt.setCurrentY(170);
//rpt.font('Aparajita');
rpt.fontItalic();
rpt.band([
{data: 'Date:', width: 78},
{data: Current_Date, width: 240},
{data: '# of Pages:', width: 78},
{data: data.number_of_pages || 2, width: 200, align: 1}
// font: Was "Times-Roman"; but CI Machine don't like the built in fonts
], {font: "Arimo", fontItalic: true, fontBold: true});
rpt.newLine();
rpt.fontNormal();
rpt.band([
{data: 'To:', width: 78},
{data: data.faxTo, width: 240},
{data: 'Attention:', width: 78},
{data: data.attention, width: 200}
]);
rpt.newLine();
rpt.band([
{data: 'From:', width: 78},
{data: data.from, width: 240},
{data: 'Phone:', width: 78},
{data: data.phone, width: 200}
]);
rpt.newLine();
rpt.newLine();
rpt.print('Comments:', {fontBold: true});
rpt.print(data.comments);
};
var footer = function(rpt) {
rpt.print(['This material is for the intended recipient.'], {fontBold: true, fontSize: 8, y: 740});
};
// If you change the callback to FALSE the report will be cancelled!
var recordCount = function(count, callback) {
console.log("We have", count, "records!");
callback(null, true);
};
// You don't have to pass in a report name; it will default to "report.pdf"
const reportName = __dirname + "/demo03.pdf";
const testing = {images: 1, blocks: ["210,330,240,60"]};
var rpt = new Report(reportName, {font: "Arimo"});
rpt.registerFont("Arimo", {normal: __dirname+'/Fonts/Arimo-Regular.ttf', bold: __dirname+'/Fonts/Arimo-Bold.ttf', italic: __dirname+'/Fonts/Arimo-Italic.ttf', bolditalic: __dirname+'/Fonts/Arimo-BoldItalic.ttf', boldItalic: __dirname+'/Fonts/Arimo-BoldItalic.ttf'});
rpt
.recordCount(recordCount)
.margins(30)
//.autoPrint(true)
.header(header)
.pageFooter(footer)
.data(options.data);
// Debug output is always nice (Optional, to help you see the structure)
if (typeof process.env.TESTING === "undefined") { rpt.printStructure(); }
// This does the MAGIC... :-)
console.time("Rendered");
rpt.render(function(err, name) {
console.timeEnd("Rendered");
if (name === false) {
console.log("Report has been cancelled!");
} else {
displayReport(err, name, testing);
}
});
}
const imgLoc = __dirname + "/example_image.jpg";
printreport({
image: imgLoc,
name: "James Smith",
company: "ACME Industries",
address: "1234 Nowhere St",
city: "Here",
state: "Texas",
postal: "0000",
data: [{
phone: "800-555-1212",
faxTo: "800-555-1211",
from: "Me",
attention: "You",
number_of_pages: 5,
comments: "Here is the proposal you wanted, it should match what we discussed on the phone. If this is acceptable; please let me know."
}]
});