Merge origin/main into origin/dev-moritz
This commit is contained in:
159
src/lib/pdf/pdfDatenblatt.ts
Normal file
159
src/lib/pdf/pdfDatenblatt.ts
Normal file
@@ -0,0 +1,159 @@
|
||||
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";
|
||||
|
||||
/* -------------------------------- 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"
|
||||
};
|
||||
|
||||
pages[0].drawText(`${benutzer.vorname} ${benutzer.name}`, {
|
||||
x: marginX,
|
||||
y: height - marginY,
|
||||
font,
|
||||
size: 12
|
||||
})
|
||||
|
||||
pages[0].drawText(benutzer.adresse, {
|
||||
x: marginX,
|
||||
y: height - marginY - 15,
|
||||
font,
|
||||
size: 12
|
||||
})
|
||||
|
||||
pages[0].drawText(`${benutzer.plz} ${benutzer.ort}`, {
|
||||
x: marginX,
|
||||
y: height - marginY - 30,
|
||||
font,
|
||||
size: 12
|
||||
})
|
||||
|
||||
pages[0].drawText("Datenblatt Energieausweis", {
|
||||
x: marginX,
|
||||
y: height - marginY - 100,
|
||||
font: bold,
|
||||
size: 12,
|
||||
})
|
||||
|
||||
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])
|
||||
|
||||
// pdf.getForm().flatten()
|
||||
|
||||
return pdf.save();
|
||||
}
|
||||
Reference in New Issue
Block a user