Neville Ausgetauscht + PDF

This commit is contained in:
Moritz Utcke
2025-01-13 11:09:20 +07:00
parent d084ed506d
commit 01b701c392
13 changed files with 500 additions and 307 deletions

View File

@@ -3,6 +3,7 @@ import { endEnergieVerbrauchVerbrauchsausweis_2016 } from "#lib/Berechnungen/Ver
import * as fs from "fs"
import { PDFDocument, rgb, StandardFonts, TextAlignment } from "pdf-lib";
import { checkbox, flex, text } from "./elements/index.js";
import { xml2pdf } from "./elements/xml2pdf.js";
/* -------------------------------- Pdf Tools ------------------------------- */
@@ -34,124 +35,140 @@ export async function pdfDatenblatt(ausweis: VerbrauchsausweisWohnenClient) {
plz: "12345",
ort: "Beispielhausen"
};
const layout = xml2pdf(`<layout height="${pages[0].getHeight()}" width="${pages[0].getWidth()}" marginTop="150" marginLeft="45" marginRight="45">
<text size="12" lineHeight="14">${benutzer.vorname} ${benutzer.name}</text>
<text size="12" lineHeight="14">${benutzer.adresse}</text>
<text size="12" lineHeight="14">${benutzer.plz} ${benutzer.ort}</text>
<flex direction="row" justify="space-between" marginTop="55" width="${pages[0].getWidth() - 90}">
<text size="12" font="bold">Datenblatt Energieausweis</text>
<text size="12">Ausweis ID: ${ausweis.uid}</text>
</flex>
<text size="12" lineHeight="14" font="bold" marginTop="10">Gebäudedaten</text>
<text size="12" lineHeight="14">Adresse: ${ausweis.gebaeude_aufnahme_allgemein.adresse}, ${ausweis.gebaeude_aufnahme_allgemein.plz} ${ausweis.gebaeude_aufnahme_allgemein.ort}</text>
pages[0].drawText(`${benutzer.vorname} ${benutzer.name}`, {
x: marginX,
y: height - marginY,
font,
size: 12
<flex direction="row" justify="space-between" width="${pages[0].getWidth() - 90}" marginTop="25">
<flex direction="row" gap="5" align="center">
<checkbox width="8" height="8"></checkbox>
<text size="12">Neubau</text>
</flex>
<flex direction="row" gap="5" align="center">
<checkbox width="8" height="8"></checkbox>
<text size="12">Vermietung/Verkauf</text>
</flex>
<flex direction="row" gap="5" align="center">
<checkbox width="8" height="8"></checkbox>
<text size="12">Modernisierung</text>
</flex>
<flex direction="row" gap="5" align="center">
<checkbox width="8" height="8"></checkbox>
<text size="12">Sonstiges</text>
</flex>
</flex>
<flex direction="row" marginTop="25" gap="15">
<flex direction="column" width="${(pages[0].getWidth() - 90) / 2 - 7.5}">
<flex direction="row" align="center" justify="space-between" width="${(pages[0].getWidth() - 90) / 2 - 7.5}">
<text size="12" lineHeight="14">Gebäudetyp:</text>
<text size="12" lineHeight="14">${ausweis.gebaeude_aufnahme_allgemein.gebaeudetyp}</text>
</flex>
<flex direction="row" align="center" justify="space-between" width="${(pages[0].getWidth() - 90) / 2 - 7.5}">
<text size="12" lineHeight="14">Wohnfläche:</text>
<text size="12" lineHeight="14">DIN Wohnfläche innen ${ausweis.gebaeude_aufnahme_allgemein.flaeche} m²</text>
</flex>
<flex direction="row" align="center" justify="space-between" width="${(pages[0].getWidth() - 90) / 2 - 7.5}">
<text size="12" lineHeight="14">Leerstand:</text>
<text size="12" lineHeight="14">${ausweis.gebaeude_aufnahme_allgemein.leerstand || 0}%</text>
</flex>
<flex direction="row" align="center" justify="space-between" width="${(pages[0].getWidth() - 90) / 2 - 7.5}">
<text size="12" lineHeight="14">Wohnungen:</text>
<text size="12" lineHeight="14">${ausweis.gebaeude_aufnahme_allgemein.einheiten}</text>
</flex>
</flex>
<flex direction="column" width="${(pages[0].getWidth() - 90) / 2 - 7.5}">
<flex direction="row" align="center" justify="space-between" width="${(pages[0].getWidth() - 90) / 2 - 7.5}">
<text size="12" lineHeight="14">Dachgeschoss:</text>
<text size="12" lineHeight="14">${ausweis.gebaeude_aufnahme_allgemein.dachgeschoss}</text>
</flex>
<flex direction="row" align="center" justify="space-between" width="${(pages[0].getWidth() - 90) / 2 - 7.5}">
<text size="12" lineHeight="14">Keller:</text>
<text size="12" lineHeight="14">${ausweis.gebaeude_aufnahme_allgemein.keller}</text>
</flex>
</flex>
</flex>
</layout>`, {
"default": font,
bold: bold
})
pages[0].drawText(benutzer.adresse, {
x: marginX,
y: height - marginY - 15,
font,
size: 12
})
layout.draw(pages[0], 0, pages[0].getHeight())
pages[0].drawText(`${benutzer.plz} ${benutzer.ort}`, {
x: marginX,
y: height - marginY - 30,
font,
size: 12
})
// const containerWidth = width - marginX;
pages[0].drawText("Datenblatt Energieausweis", {
x: marginX,
y: height - marginY - 100,
font: bold,
size: 12,
})
// const layout = flex([
// flex([
// checkbox(8, 8), text("Neubau", {
// color: rgb(0,0,0),
// font,
// fontSize: 12
// })
// ], {
// align: "center",
// justify: "center",
// gap: 5,
// height: 12,
// page: pages[0]
// }),
// flex([
// checkbox(8, 8), text("Vermietung/Verkauf", {
// color: rgb(0,0,0),
// font,
// fontSize: 12
// })
// ], {
// align: "center",
// justify: "center",
// gap: 5,
// height: 12,
// page: pages[0]
// }),
// flex([
// checkbox(8, 8), text("Modernisierung", {
// color: rgb(0,0,0),
// font,
// fontSize: 12
// })
// ], {
// align: "center",
// justify: "center",
// gap: 5,
// height: 12,
// page: pages[0]
// }),
// flex([
// checkbox(8, 8), text("Sonstiges", {
// color: rgb(0,0,0),
// font,
// fontSize: 12
// })
// ], {
// align: "center",
// justify: "center",
// gap: 5,
// height: 12,
// page: pages[0]
// })
// ], {
// align: "center",
// justify: "space-between",
// gap: 15,
// x: marginX,
// y: height - marginY - 165,
// height: 12,
// width: containerWidth
// })
let ausweisIDText = `Ausweis ID: ${ausweis.uid}`
pages[0].drawText(ausweisIDText, {
x: width - marginX - font.widthOfTextAtSize(ausweisIDText, 12),
y: height - marginY - 100,
font,
size: 12,
})
pages[0].drawText("Gebäudedaten", {
x: marginX,
y: height - marginY - 125,
font: bold,
size: 12,
})
pages[0].drawText(`Adresse: ${ausweis.gebaeude_aufnahme_allgemein.adresse}, ${ausweis.gebaeude_aufnahme_allgemein.plz} ${ausweis.gebaeude_aufnahme_allgemein.ort}`, {
x: marginX,
y: height - marginY - 140,
font,
size: 12,
})
const containerWidth = width - marginX;
const layout = flex([
flex([
checkbox(8, 8), text("Neubau", {
color: rgb(0,0,0),
font,
fontSize: 12
})
], {
align: "center",
justify: "center",
gap: 5,
height: 12,
page: pages[0]
}),
flex([
checkbox(8, 8), text("Vermietung/Verkauf", {
color: rgb(0,0,0),
font,
fontSize: 12
})
], {
align: "center",
justify: "center",
gap: 5,
height: 12,
page: pages[0]
}),
flex([
checkbox(8, 8), text("Modernisierung", {
color: rgb(0,0,0),
font,
fontSize: 12
})
], {
align: "center",
justify: "center",
gap: 5,
height: 12,
page: pages[0]
}),
flex([
checkbox(8, 8), text("Sonstiges", {
color: rgb(0,0,0),
font,
fontSize: 12
})
], {
align: "center",
justify: "center",
gap: 5,
height: 12,
page: pages[0]
})
], {
align: "center",
justify: "space-between",
gap: 15,
x: marginX,
y: height - marginY - 165,
height: 12,
width: containerWidth
})
layout.draw(pages[0])
// layout.draw(pages[0])
// pdf.getForm().flatten()