-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-pdf.js
More file actions
104 lines (95 loc) · 3.63 KB
/
build-pdf.js
File metadata and controls
104 lines (95 loc) · 3.63 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
'use strict';
var Printer = require('pdfmake'),
_ = require('lodash'),
path = require('path');
function fontPath(file) {
return path.resolve('roboto', file);
}
module.exports = {
create: function(image,addresses,slug) {
var table = [];
_.forEach(_.groupBy(addresses,'street'), function(value, key) {
table.push([
{text: key, style:'streetLocalityHR1'},
{text: 'Unable to knock', style:['streetLocalityHR1','streetLocalityHR2']},
{text: 'Not Home', style:['streetLocalityHR1','streetLocalityHR2']},
{text: 'Not Interested', style:['streetLocalityHR1','streetLocalityHR2']},
{text: 'Meaningful Conversation', style:['streetLocalityHR1','streetLocalityHR2']},
]);
_.forEach(value, function(adr) {
table.push([
[{text: adr.street_number, bold: true, fontSize: 10},{text: adr.gnaf_pid, fontSize: 6}],
{canvas:[{type: 'rect',x: 20,y: 2.5,w: 10,h: 10,r: 3,lineWidth: 1,lineColor: '#000000'}]},
{canvas:[{type: 'rect',x: 20,y: 2.5,w: 10,h: 10,r: 3,lineWidth: 1,lineColor: '#000000'}]},
{canvas:[{type: 'rect',x: 20,y: 2.5,w: 10,h: 10,r: 3,lineWidth: 1,lineColor: '#000000'}]},
{canvas:[{type: 'rect',x: 20,y: 2.5,w: 10,h: 10,r: 3,lineWidth: 1,lineColor: '#000000'}]}
])
})
});
var docDefinition = {
pageSize: 'A4',
pageOrientation: 'portrait',
/*
background: function(currentPage) {
console.log(currentPage);
var image = '';
if (currentPage > 2) { image = 'baselayer.png' }
return { image: image }
},
*/
// [left, top, right, bottom] or [horizontal, vertical] or just a number for equal margins
pageMargins: [ 30, 75, 30, 30 ],
watermark: {text: slug, color: '#000000', opacity: 0.1, bold: true, italics: false},
content: [
{
image: image,
fit: [595, 250]
},
{
style: 'table',
table: {
headerRows: 0,
dontBreakRows: true,
widths: [ '20%', '*', '*', '*', '*'],
body: table
}
}
],
styles: {
streetLocalityHR1: {
fontSize: 10,
bold: true,
// color: '#fff',
// fillColor: '#555',
alignment: 'center'
},
streetLocalityHR2: {
fontSize: 7
},
pageHeader: {
alignment: 'left',
fontSize: 22,
margin: [0, 5, 0, 15]
},
table: {
margin: [0, 0, 0, 0]
}
},
defaultStyle: {
alignment: 'center',
fontSize: 11
}
};
var fontDescriptors = {
Roboto: {
normal: fontPath('RobotoCondensed-Regular.ttf'),
bold: fontPath('RobotoCondensed-Bold.ttf'),
italics: fontPath('RobotoCondensed-Italic.ttf'),
bolditalics: fontPath('RobotoCondensed-Italic.ttf')
}
};
var printer = new Printer(fontDescriptors);
var pdfDoc = printer.createPdfKitDocument(docDefinition);
return pdfDoc;
}
};