176 lines
6.2 KiB
TypeScript
176 lines
6.2 KiB
TypeScript
import { VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
|
|
import { endEnergieVerbrauchVerbrauchsausweis_2016 } from "#lib/Berechnungen/VerbrauchsausweisWohnen/VerbrauchsausweisWohnen_2016.js";
|
|
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 ------------------------------- */
|
|
|
|
export async function pdfDatenblatt(ausweis: VerbrauchsausweisWohnenClient) {
|
|
const VerbrauchsausweisWohnenGEG2024PDF = fs.readFileSync(new URL("./templates/Leerseite_Datenblatt.pdf", import.meta.url), "base64");
|
|
const pdf = await PDFDocument.load(VerbrauchsausweisWohnenGEG2024PDF)
|
|
const pages = pdf.getPages()
|
|
|
|
// const template = VerbrauchsausweisWohnen2016Template as Template;
|
|
|
|
const berechnungen = await endEnergieVerbrauchVerbrauchsausweis_2016(ausweis);
|
|
|
|
const height = pages[0].getHeight()
|
|
const width = pages[0].getWidth()
|
|
|
|
const font = await pdf.embedFont(StandardFonts.Helvetica)
|
|
const bold = await pdf.embedFont(StandardFonts.HelveticaBold)
|
|
|
|
const form = pdf.getForm()
|
|
form.updateFieldAppearances(font)
|
|
|
|
const marginX = 45;
|
|
const marginY = 150;
|
|
|
|
const benutzer: typeof ausweis.benutzer = ausweis.benutzer || {
|
|
vorname: "Max",
|
|
name: "Mustermann",
|
|
adresse: "Musterstraße 123",
|
|
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>
|
|
|
|
<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
|
|
})
|
|
|
|
layout.draw(pages[0], 0, pages[0].getHeight())
|
|
|
|
// 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])
|
|
|
|
// pdf.getForm().flatten()
|
|
|
|
return pdf.save();
|
|
} |