pdf1.js
11.7 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
class PDF1 {
"use strict";
constructor() {
/** Coordinate container that occupies the whole page **/
this.A4 = new Div(
new Vector(0, 0),
/*invierto por apaisada*/
new Vector(842,595)
);
this.containerSize = 86;
this.body = {
"font": "times",
"type": "normal",
"size": 10
};
this.title = {
"font": "times",
"type": "bold",
"size": 11
};
this.subtitle = {
"font": "times",
"type": "bold",
"size": 10
};
this.line = () => new Line(
new Vector(Pos.beg_margin, Pos.end),
new Vector(Pos.end_margin + 3, Pos.end)
);
}
_getdata(data, op, n) {
switch (op.toLowerCase()) {
case "fi":
op = "fuerza_izquierda";break;
case "fd":
op = "fuerza_derecha";break;
case "ri":
op = "resistencia_izquierda";break;
case "rd":
op = "resistencia_derecha";break;
case "oi":
op = "ovalidad_izquierda";break;
case "od":
op = "ovalidad_derecha";break;
case "pe":
op = "peso_estatico";break;
case "pd":
op = "peso_dinamico";break;
}
return data[op + "_" + n];
}
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),
//(pointer, data) => pdfthis.gaseshumosToPDF(pointer, data['gaseshumos']),
(pointer, data) => pdfthis.TablaToPDF(pointer, data),
(pointer, data) => pdfthis.footerToPDF(pointer, data)
];
/**
* 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;
}
TablaToPDF(pointer, data) {
var origen = [50,50]
const container = this.A4.addRelativeChild(new Div({"x":20,"y":50}, new Vector(Pos.end, 25)));
// Crear las celdas y títulos
for (var i = 0; i < 4; i++) {
// Crear una fila (div con clase "row")
var row = new Div(pointer, new Vector(origen, origen[1]));
for (var j = 0; j < 3; j++) {
// Crear una celda (div con clase "cell")
console.log(pointer)
var cell = new Div(pointer, new Vector(origen[1] + 5, 6));
//cell.className = "cell";
// Agregar el título a las celdas de la primera fila
cell.addRelativeChild(
new Text(
"gdfdgfgdf" + j,
new Vector(origen[1] + 5, Pos.third),
this.title
)
)
// Agregar la celda a la fila
row.addRelativeChild(cell);
}
// Agregar la fila al contenedor
container.addRelativeChild(row);
}
return pointer.addxy(0,6);
}
mahaToPDF(pointer, data) {
const maha = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 6)));
maha.addRelativeChildren([
//this.line(),
/**
new Text(
["MAHA","EUROSYSTEM","Bitte hier Ihre","Anschrift eintragen"],
new Vector(Pos.middle, Pos.quarter),
this.body,
"center"
),
*/
new Text(
["EUROSYSTEM","V 7.20.029"],
new Vector(Pos.end_margin - 8, Pos.third + 4),
this.body,
"right"
),
new Image(
//Logo de MaHA
document.getElementById("maha"),
new Vector(Pos.end - 12, Pos.beg_margin),
new Vector(10, Pos.end_margin - 5)
)
]);
return pointer.addxy(0,6);
}
headerToPDF(pointer, data) {
const header = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 10)));
const body_black = {
"font" : "times",
"type" : "bold",
"size" : 9
};
header.addRelativeChildren([
//this.line(),
new Text(
[
`\t\t\t\t Auto`,
"Nombre/Empresa:",
"Calle:",
"C.P.Ciudad:",
"Teléfono:",
`Fecha de Prueba:\t${data['fecha']}`,
`Hora de Prueba:\t${data['hora']}`,
`Ingeniero:\t${data['ingeniero']}`,
"Estado de Carga:"
],
new Vector(Pos.beg_margin + 5, Pos.beg_margin + 10),
body_black
),
new Text(
[
`\t\t\t Auto`,
`Matrícula:\t${data['patente']}`,
"Kilometraje:",
"Matriculación:\t/ /",
"Fabricante:",
"Tipo de Vehic.:",
"Nº chasis:",
"Cantidad de Ejes:\t2" /*capas aca hay q poner variable */
],
new Vector(Pos.two_thirds - 15 , Pos.beg_margin + 10), /*Agregar un corrector para achicar*/
body_black
)
]);
return pointer.addxy(0, 10);
}
alineadorToPDF(pointer, data) {
const alineador = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 25)));
alineador.addRelativeChildren([
//this.line(),
new Text(
"Alineador al Paso",
new Vector(Pos.beg_margin + 5, Pos.third),
this.title
),
new Text(
`Eje delantero\t${data['eje_delantero']} m/km\t\tEje trasero\t--- m/km`,
new Vector(Pos.beg_margin + 5, Pos.two_thirds),
this.body
)
]);
return pointer.addxy(0, 6);
}
suspensionToPDF(pointer, data) {
const suspension = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 8)));
const tiny_body = {
"font" : "times",
"type" : "normal",
"size" : 9
}
suspension.addRelativeChildren([
//this.line(),
new Text(
"Bco. de Suspensiones",
new Vector(Pos.beg_margin + 5, Pos.third),
this.title
),
new Text(
["Eje delantero", "Eje trasero"],
new Vector(Pos.beg_margin + 5, Pos.two_thirds),
this.subtitle
),
new Text(
["Izq.", "--- Mm", "--- Mm"],
new Vector(30, Pos.middle + 5),
tiny_body,
"center"
),
new Text(
["Der.", "--- Mm", "--- Mm"],
new Vector(45, Pos.middle + 5),
tiny_body,
"center"
),
new Text(
["Izq.", `${data['rendimiento_izquierdo_1']} %`, `${data['rendimiento_izquierdo_2']} %`],
new Vector(60, Pos.middle + 5),
tiny_body,
"center"
),
new Text(
["Der.", `${data['rendimiento_derecho_1']} %`, `${data['rendimiento_derecho_2']} %`],
new Vector(75, Pos.middle + 5),
tiny_body,
"center"
),
new Text(
["Peso", `${data['peso_estatico_1']} kg`, `${data['peso_estatico_2']} kg`],
new Vector(90, Pos.middle + 5),
tiny_body,
"center"
)
]);
return pointer.addxy(0, 8);
}
frenosToPDF(pointer, data) {
const frenos = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 30)));
frenos.addRelativeChild(this.line());
const pruebas = frenos.addRelativeChild(new Div(new Vector(Pos.beg, Pos.beg), new Vector(Pos.end, Pos.middle + 10)));
const evaluacion = frenos.addRelativeChild(new Div(new Vector(Pos.beg, Pos.middle + 10), new Vector(Pos.end, Pos.middle - 10)));
const tiny_body = {
"font": "times",
"type": "normal",
"size": 9
}
pruebas.addRelativeChildren([
new Text(
"Frenómetro",
new Vector(Pos.beg_margin + 5, Pos.beg_margin + 5),
this.title
),
new Text(
"Prueba de Frenado",
new Vector(Pos.beg_margin + 5, Pos.beg_margin + 15),
this.subtitle
),
new Line(
new Vector(Pos.beg_margin + 5, Pos.quarter + 18),
new Vector(Pos.end_margin - 5, Pos.quarter + 18)
),
new Text(
["","", "1.FS", "2.FS", "3.FS", "4.FS", `${data['trasero']['eje']}.FE`],
new Vector(Pos.beg_margin + 5, Pos.quarter + 12),
tiny_body
),
new Text(
"Resist.Rodadura [kN]",
new Vector(21, Pos.quarter + 5),
tiny_body
),
new Text(
"Fuerza de Frenado [kN]",
new Vector(40, Pos.quarter + 5),
tiny_body
),
new Text(
"Ovalidad [kN]",
new Vector(60.5, Pos.quarter + 5),
tiny_body
),
new Text(
"Peso [kg]",
new Vector(79, Pos.quarter + 5),
tiny_body
),
]);
const freno = (title, data, access, position) => {
const f = data['frenos'];
const t = data['trasero'][access] === undefined ? "---" : data['trasero'][access];
return new Text(
[title, "", f[access + "_1"], f[access + "_2"], f[access + "_3"], f[access + "_4"], t],
position,
tiny_body,
"center"
)
}
const eje = (data, position) => {
const sum = (data, access1, access2) => {
const a = parseFloat(data[access1]);
const b = parseFloat(data[access2]);
let sum = 0.0;
if (isNaN(a)) return data[access1];
sum += a;
if (isNaN(b)) return sum.toFixed(2);
sum += b;
return sum.toFixed(2);
}
const f = data['frenos'];
const t = data['trasero'];
return new Text(
[
"Eje", "",
`${sum(f,"fuerza_izquierda_1","fuerza_derecha_1")}`,
`${sum(f,"fuerza_izquierda_2","fuerza_derecha_2")}`,
`${sum(f,"fuerza_izquierda_3","fuerza_derecha_3")}`,
`${sum(f,"fuerza_izquierda_4","fuerza_derecha_4")}`,
`${sum(t,"fuerza_izquierda","fuerza_derecha")}`,
],
position,
tiny_body,
"center"
)
}
const fuerzas = eje(data, new Vector(53, Pos.quarter + 12));
const peso = freno("Total", data, "peso_estatico", new Vector(82, Pos.quarter + 12));
pruebas.addRelativeChildren([
freno("Izq.", data, "resistencia_izquierda", new Vector(24, Pos.quarter + 12)),
freno("Der.", data, "resistencia_derecha", new Vector(30, Pos.quarter + 12)),
freno("Izq.", data, "fuerza_izquierda", new Vector(42, Pos.quarter + 12)),
freno("Der.", data, "fuerza_derecha", new Vector(48, Pos.quarter + 12)),
fuerzas,
freno("Izq.", data, "ovalidad_izquierda", new Vector(62, Pos.quarter + 12)),
freno("Der.", data, "ovalidad_derecha", new Vector(68, Pos.quarter + 12)),
peso,
]);
const sumtext = (text) => {
const a = parseFloat(text[2]);
const b = parseFloat(text[3]);
const c = parseFloat(text[4]);
const d = parseFloat(text[5]);
let sum = 0.0;
if (isNaN(a)) return text[2];
sum += a;
if (isNaN(b)) return sum.toFixed(2);
sum += b;
if (isNaN(c)) return sum.toFixed(2);
sum += c;
if (isNaN(d)) return sum.toFixed(2);
sum += d;
return sum.toFixed(2);
}
evaluacion.addRelativeChildren([
new Text(
"Evaluación Final",
new Vector(Pos.beg_margin + 5, Pos.beg_margin),
this.subtitle
),
new Text(
["Freno de Servicio (FS)", "Freno de Estacionamiento (FE)"],
new Vector(Pos.beg_margin + 5, Pos.quarter + 10),
this.body
),
new Text(
[
"Fuerza de frenado máx. [kN]",
`${sumtext(fuerzas.text)}`,
fuerzas.text[6]
],
new Vector(Pos.middle, Pos.quarter),
this.body,
"center"
),
new Text(
`Peso total:\t${sumtext(peso.text)} kg`,
new Vector(Pos.beg_margin + 5, Pos.three_quarters),
this.body
)
]);
return pointer.addxy(0, 30);
}
gaseshumosToPDF(pointer, data) {
const gases = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 6)));
const tiny_body = {
"font": "times",
"type": "normal",
"size": 9
}
gases.addRelativeChildren([
this.line(),
new Text(
"Gases",
new Vector(Pos.beg_margin + 5, Pos.third),
this.title
),
new Text(
`k medio\t${data['opacidad_logaritmica']} l/m\tCO:\t${data['co']}\tHC:\t${data['hc']}`,
new Vector(Pos.beg_margin + 5, Pos.two_thirds),
tiny_body
),
]);
return pointer.addxy(0,6);
}
footerToPDF(pointer, data) {
const footer = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 30)));
footer.addRelativeChildren([
//this.line(),
new Text(
"Inspector:",
new Vector(Pos.quarter - 5, Pos.end_margin),
this.subtitle,
"center"
),
new Text(
"Firma:.........................",
new Vector(Pos.three_quarters, Pos.end_margin),
this.subtitle,
"center"
)
]);
return pointer.addxy(0,30);
}
}