pdf2.js
8.57 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
class PDF2 {
"use strict";
constructor() {
/** Coordinate container that occupies the whole page **/
this.A4 = new Div(
new Vector(0, 0),
new Vector(842,595)
);
this.containerSize = 86;
this.font = {
"font": "courier",
"type": "normal",
"size": 10
};
this.Dominio = ""
}
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;
console.log(data)
const functionMapping = [
(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']),
(pointer, data) => pdfthis.ruidoToPDF(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;
}
todosValoresIguales(obj) {
// Obtener todos los valores del objeto en un array
const valores = Object.values(obj);
// Verificar si todos los valores son iguales
for (let i = 1; i < valores.length; i++) {
if (valores[i] !== valores[0]) {
return true; // Al menos un valor es diferente
}
}
return false; // Todos los valores son iguales
}
headerToPDF(pointer, data) {
//const header = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 5)));
this.Dominio = data['patente'].toUpperCase()
//header.addRelativeChildren([
// new Text("Dominio: " + data['patente'], new Vector(Pos.beg_margin , Pos.third), this.font),
// new Text("Ingeniero: " + data['ingeniero'], new Vector(Pos.quarter + 4, Pos.third), this.font),
// new Text("Fecha y hora " + data['fecha'] + " " + data['hora'], new Vector(Pos.third + 30, Pos.third), this.font)
//]);
//return pointer.addxy(0, 3);
return pointer
}
alineadorToPDF(pointer, data) {
//const alineador = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 5)));
//alineador.addRelativeChildren([
//new Text("Resultado Pruebas en Banco de Alineador al Paso", new Vector(Pos.beg_margin + 2, Pos.third), this.font),
//new Text("Eje Delantero", new Vector(Pos.beg_margin + 2, Pos.two_thirds), this.font),
//new Text(data['eje_delantero'], new Vector(Pos.quarter, Pos.two_thirds), this.font)
//]);
//return pointer.addxy(0, 5);
return pointer
}
suspensionToPDF(pointer, data) {
const suspension = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 15)));
const divsize = new Vector(this.containerSize, Pos.middle);
const ejes = suspension.addRelativeChildren([
new Div(new Vector(Pos.beg_margin + 2, Pos.beg), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.middle), divsize)
]);
const table = (container, eje, RI, peso, RD) => {
container.addRelativeChildren([
new Text(`${this.Dominio} - Resultado Pruebas en Banco de Suspensión - Eje ${eje}`, new Vector(0, Pos.third, ), this.font),
new Text("Rendimiento Izquierdo", new Vector(Pos.beg, Pos.two_thirds), this.font),
new Text(RI, new Vector(Pos.beg + 10, Pos.end, ), this.font),
new Text("Peso Total del Eje", new Vector(Pos.middle - 10, Pos.two_thirds), this.font),
new Text(peso, new Vector(Pos.middle - 3, Pos.end), this.font),
new Text("Rendimiento Derecho", new Vector(Pos.three_quarters - 5, Pos.two_thirds), this.font),
new Text(RD, new Vector(Pos.three_quarters + 5, Pos.end), this.font)
]);
};
for (let i = 0; i < 2; i++) {
table(
ejes[i],
i + 1,
data[`rendimiento_izquierdo_${i+1}`],
data[`peso_estatico_${i+1}`],
data[`rendimiento_derecho_${i+1}`]
);
}
return pointer.addxy(0, 15);
}
frenosToPDF(pointer, data) {
const frenos = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 60)));
const divsize = new Vector(this.containerSize, Pos.quarter);
const ejes = frenos.addRelativeChildren([
new Div(new Vector(Pos.beg_margin + 2, Pos.beg), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.quarter), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.middle), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.three_quarters), divsize)
]);
const table = (container, eje, FI, RI, OI, peso, FD, RD, OD) => {
if (FI === RI === OI === peso === FD === RD === OD) {
console.log(eje)
} else {
container.addRelativeChildren([
new Text(`${this.Dominio} - Diagnóstico de Frenos - Eje ${eje}`, new Vector(Pos.beg, Pos.beg_margin + 10), this.font),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.quarter), this.font),
new Text(`${FI} KN`, new Vector(Pos.beg_margin + 3, Pos.quarter + 10), this.font),
new Text("Res.Rodadura IZ", new Vector(Pos.beg_margin, Pos.middle), this.font),
new Text(`${RI} Kg`, new Vector(Pos.beg_margin + 3, Pos.middle + 10), this.font),
new Text("Ovalidad IZ", new Vector(Pos.beg_margin, Pos.three_quarters), this.font),
new Text(`${OI}`, new Vector(Pos.beg_margin + 3, Pos.three_quarters + 10), this.font),
new Text("Peso del Eje", new Vector(Pos.middle - 10, Pos.middle), this.font),
new Text(`${peso} Kg`, new Vector(Pos.middle - 5, Pos.middle + 10), this.font),
new Text("Diferencia ", new Vector(Pos.middle - 10, Pos.quarter), this.font),
new Text(`${peso} %`, new Vector(Pos.middle - 5, Pos.quarter + 10), this.font),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.quarter), this.font),
new Text(`${FD} KN`, new Vector(Pos.three_quarters + 3, Pos.quarter + 10), this.font),
new Text("Res.Rodadura DE", new Vector(Pos.three_quarters, Pos.middle), this.font),
new Text(`${RD} Kg`, new Vector(Pos.three_quarters + 3, Pos.middle + 10), this.font),
new Text("Ovalidad DE", new Vector(Pos.three_quarters, Pos.three_quarters), this.font),
new Text(`${OD}`, new Vector(Pos.three_quarters + 3, Pos.three_quarters + 10), this.font)
]);
}
};
for (let i = 0; i < ejes.length; i++) {
table(
ejes[i],
i + 1,
data[`fuerza_izquierda_${i + 1}`],
data[`resistencia_izquierda_${i + 1}`],
data[`ovalidad_izquierda_${i + 1}`],
data[`peso_estatico_${i + 1}`],
data[`fuerza_derecha_${i + 1}`],
data[`resistencia_derecha_${i + 1}`],
data[`ovalidad_derecha_${i + 1}`]
);
}
return pointer.addxy(0, 60);
}
traseroToPDF(pointer, data) {
const trasero = this.A4.addRelativeChild(new Div(pointer.addxy(Pos.beg_margin + 2, 0), new Vector(this.containerSize, 9)));
trasero.addRelativeChildren([
new Text(`${this.Dominio} - Diagnóstico de Frenos - Eje Trasero - Frenos de Mano`, new Vector(Pos.beg, Pos.third, ), this.font),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.two_thirds), this.font),
new Text(data['fuerza_izquierda'], new Vector(Pos.beg_margin, Pos.end), this.font),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.two_thirds), this.font),
new Text(data['fuerza_derecha'], new Vector(Pos.three_quarters, Pos.end), this.font),
]);
return pointer.addxy(0, 9);
}
gaseshumosToPDF(pointer, data) {
const gaseshumos = this.A4.addRelativeChild(new Div(pointer.addxy(Pos.beg_margin + 2, 0), new Vector(this.containerSize, 9)));
gaseshumos.addRelativeChildren([
new Text(`${this.Dominio} - Resultado Analizador de Gases`, new Vector(Pos.beg, Pos.third), this.font),
new Text(`${this.Dominio} - Resultado Analizador de Humos`, new Vector(Pos.two_thirds, Pos.third), this.font),
new Text(`CO ${data['co']} % HC ${data['hc']} ppm`, new Vector(Pos.beg, Pos.two_thirds), this.font),
new Text(`Medición ${data['opacidad_logaritmica']}`, new Vector(Pos.three_quarters, Pos.two_thirds), this.font)
]);
return pointer.addxy(0, 9);
}
ruidoToPDF(pointer, data) {
const gaseshumos = this.A4.addRelativeChild(new Div(pointer.addxy(Pos.beg_margin + 2, 0), new Vector(this.containerSize, 9)));
gaseshumos.addRelativeChildren([
new Text(`${this.Dominio} - Resultado Analizador Ruido`, new Vector(Pos.beg, Pos.third), this.font),
new Text("", new Vector(Pos.two_thirds, Pos.third), this.font),
new Text(` ${data['co']} dba`, new Vector(Pos.beg, Pos.two_thirds), this.font),
new Text("", new Vector(Pos.three_quarters, Pos.two_thirds), this.font)
]);
return pointer.addxy(0, 9);
}
}