pdf3.js
2.27 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
class PDF3 {
"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.body = {
"font": "times",
"type": "normal",
"size": 9
};
this.title = {
"font": "times",
"type": "bold",
"size": 13
};
this.subtitle = {
"font": "times",
"type": "bold",
"size": 8
};
this.line = () => new Line(
new Vector(Pos.beg_margin, Pos.end),
new Vector(Pos.end_margin, Pos.end)
);
}
pdf(data) {
let pointer = new Vector(0,0);
pointer = this.header(pointer, data['header']);
Object.keys(data['anomalies']).forEach( title =>
pointer = this.table(
pointer, title, data['anomalies'][title]
)
);
return this.A4;
}
header(pointer, data) {
const header = this.A4.addRelativeChild( new Div(pointer, new Vector(Pos.end, 10)) );
header.addRelativeChildren([
this.line(),
new Text(
"Informe para Taller de Mantenimiento",
new Vector(Pos.middle, Pos.third),
this.title,
"center"
),
new Text(
`Fecha: ${data['fecha']}`,
new Vector(Pos.end_margin, Pos.two_thirds),
this.body,
"right"
),
new Text(
[`Razon social: ${data['cp']} - ${data['rsocial']}`, `Patente: ${data['patente']}`],
new Vector(Pos.beg_margin, Pos.two_thirds),
this.body
)
])
return pointer.addxy(0,10);
}
table(pointer, title, data) {
const table = this.A4.addRelativeChild( new Div(pointer.addxy(5,1), new Vector(90, 2 * (data.length + 1))) );
const left = table.addRelativeChild( new Div(new Vector(0,0), new Vector(30, 100)) );
const right = table.addRelativeChild( new Div(new Vector(30,0), new Vector(70, 100)) );
left.drawOutline = true;
right.drawOutline = true;
left.addRelativeChild(
new Text(
title,
new Vector(Pos.middle, Pos.middle + 10),
this.subtitle,
"center"
)
)
let subpointer = right.position.addxy(5, 0.025 * this.A4.size.y);
data.forEach( entry => {
right.addAbsoluteChild(
new Text(
`${entry['description']} - ${entry['severity']}`,
subpointer,
this.body,
)
);
subpointer = subpointer.addxy(0, 0.02 * this.A4.size.y);
});
return pointer.addxy(0, 2 * (data.length + 1) + 1);
}
}