pdf2.js
2.16 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
class PDF2 {
"use strict";
constructor() {
/** Coordinate container that occupies the whole page **/
this.A4 = new Div(
new Vector(0, 0),
new Vector(595, 842)
);
this.containerSize = 86;
this.font = {
"font": "times",
"type": "normal",
"size": 10
};
}
pdf(data) {
/**
* The lambdas serve as "apply" functions
* Each function processes an element, executed in order of appeareance in HTML.
* They all return a coordinate "pointer" to draw.
*/
const pdfthis = this;
const functionMapping = [
(pointer, data) => pdfthis.mahaToPDF(pointer, data['header']),
(pointer, data) => pdfthis.headerToPDF(pointer, data['header']),
(pointer, data) => pdfthis.alineadorToPDF(pointer, data['alineador']),
(pointer, data) => pdfthis.suspensionToPDF(pointer, data['suspension']),
(pointer, data) => pdfthis.frenosToPDF(pointer, data['frenos']),
(pointer, data) => pdfthis.traseroToPDF(pointer, data['trasero']),
(pointer, data) => pdfthis.gaseshumosToPDF(pointer, data['gaseshumos'])
];
/**
* We pass the pointer to each function, which then modify it and passes it to the next,
* We start with (0%,0%)
*/
functionMapping.reduce(
(pointer, treeMaker) => treeMaker(pointer, data),
pdfthis.A4.position
);
return this.A4;
}
mahaToPDF(pointer, data) {
const maha = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 6)));
maha.addRelativeChildren([
new Line(
new Vector(Pos.beg_margin, Pos.end),
new Vector(Pos.end_margin, Pos.end)
),
new Text(
["MAHA","EUROSYSTEM","Bitte hier Ihre","Anschrift eintragen"],
new Vector(Pos.middle, Pos.quarter),
this.font,
"center"
),
new Text(
["EUROSYSTEM","V 3.18.009",data['fecha']],
new Vector(Pos.three_quarters, Pos.middle),
this.font,
"right"
),
new Image(
document.getElementById("maha"),
new Vector(Pos.end - 10, Pos.beg_margin),
new Vector(10, Pos.end_margin)
)
]);
}
headerToPDF(pointer, data) {
}
alineadorToPDF(pointer, data) {
}
suspensionToPDF(pointer, data) {
}
frenosToPDF(pointer, data) {
}
traseroToPDF(pointer, data) {
}
gaseshumosToPDF(pointer, data) {
}
}