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
|
import * as html_to_pdf from "html-pdf-node"
import { prepare, gettimefromintervalls } from "./main.js"
import { c, writePDF } from './files.js'
let date = new Date();
date = date.toLocaleDateString("de-DE", {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
});
let hinweise = "<ul>";
for (let hinweis of c.hinweise) {
hinweise += `<li>${hinweis}</li>`;
}
hinweise += `</ul>`;
const options = {
format: 'A4',
landscape: true,
margin: {
top: "0.5cm",
right: "1cm",
bottom: "1cm",
left: "2cm",
},
};
function format() {
let tage_runtimes = prepare()
let timeout = {}
let res = "";
// 1h has 4 15 minute intervalls: 08 to 19 means 44 intervalls
for (let i = 0; i < 44; i++) {
let mensa = "";
if (11 < i && i < 25) mensa = "mensa1";
if (25 < i && i < 27) mensa = "mensa2";
res += `<tr class="${mensa}">` + gettimefromintervalls(i)
for (let day in tage_runtimes) {
if (timeout[day] > 0) {
timeout[day]--;
continue;
}
let el = tage_runtimes[day][0];
if (el.name.includes("STYLECLASS")) {
let styleclass = el.name.split("/")[1].trim().toLowerCase();
res += `<td rowspan="${el.runtime}" class="${styleclass}"></td>`;
} else {
let name = el.name == "BUFFER" ? "" : `<div><span>${el.name}</span>`;
let raum = el.raum == "BUFFER" ? "" : `<span>${el.raum}</span>`;
res += `<td rowspan="${el.runtime}">${name}${raum}</td>`;
}
timeout[day] = el.runtime - 1;
tage_runtimes[day].splice(0, 1);
}
res += "</tr>"
}
return res
}
function generatePDF() {
let html = `
${c.style}
<p>Persönlicher Stundenplan von ${c.student} für das ${c.semester}. Stand: ${date}.</p>
<table>
<tr>
<th>Uhrzeit</th>
<th class="tag">Montag</th>
<th class="tag">Dienstag</th>
<th class="tag">Mittwoch</th>
<th class="tag">Donnerstag</th>
<th class="tag">Freitag</th>
</tr>
${format()}
</table>
<br>
<em>Hinweise:</em>
${hinweise}
`;
html_to_pdf.generatePdf({content: html}, options).then(pdfBuffer => {writePDF(pdfBuffer)});
}
generatePDF()
|