Fehler Behoben
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { AufnahmeClient, BenutzerClient, ObjektClient, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
|
||||
import { AufnahmeClient, BenutzerClient, BildClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, 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";
|
||||
@@ -6,12 +6,16 @@ import { xml2pdf } from "./elements/xml2pdf.js";
|
||||
import moment from "moment";
|
||||
import { Heizungsstatus } from "@ibcornelsen/database/server";
|
||||
import { endEnergieVerbrauchVerbrauchsausweisGewerbe_2016 } from "#lib/Berechnungen/VerbrauchsausweisGewerbe/VerbrauchsausweisGewerbe_2016.js";
|
||||
import { fileURLToPath } from "url";
|
||||
import { copyPage } from "./utils/copyPage.js";
|
||||
|
||||
/* -------------------------------- Pdf Tools ------------------------------- */
|
||||
|
||||
export async function pdfDatenblattVerbrauchsausweisGewerbe(ausweis: VerbrauchsausweisGewerbeClient, aufnahme: AufnahmeClient, objekt: ObjektClient, benutzer: BenutzerClient) {
|
||||
export async function pdfDatenblattVerbrauchsausweisGewerbe(ausweis: VerbrauchsausweisGewerbeClient, aufnahme: AufnahmeClient, objekt: ObjektClient, benutzer: BenutzerClient, bilder: UploadedGebaeudeBild[]) {
|
||||
const VerbrauchsausweisWohnenGEG2024PDF = fs.readFileSync(new URL("./templates/Leerseite_Datenblatt.pdf", import.meta.url), "base64");
|
||||
const pdf = await PDFDocument.load(VerbrauchsausweisWohnenGEG2024PDF)
|
||||
const page3 = copyPage(pdf.getPages()[0]);
|
||||
pdf.addPage(page3);
|
||||
const pages = pdf.getPages()
|
||||
|
||||
// const template = VerbrauchsausweisWohnen2016Template as Template;
|
||||
@@ -135,7 +139,7 @@ export async function pdfDatenblattVerbrauchsausweisGewerbe(ausweis: Verbrauchsa
|
||||
</flex>
|
||||
<flex direction="row" align="center" justify="space-between" width="${(innerWidth) / 2 - 7.5}">
|
||||
<text size="12" lineHeight="14">Anlage zur Kühlung:</text>
|
||||
<text size="12" lineHeight="14">${ausweis.wird_gekuehlt ? "Ja" : "Nein"}</text>
|
||||
<text size="12" lineHeight="14">${aufnahme.kuehlung ? "Ja" : "Nein"}</text>
|
||||
</flex>
|
||||
<flex direction="row" align="center" justify="space-between" width="${(innerWidth) / 2 - 7.5}">
|
||||
<text size="12" lineHeight="14">Leerstand:</text>
|
||||
@@ -348,8 +352,39 @@ export async function pdfDatenblattVerbrauchsausweisGewerbe(ausweis: Verbrauchsa
|
||||
bold
|
||||
})
|
||||
|
||||
layout.draw(pages[0], 0, pages[0].getHeight())
|
||||
layoutPage2.draw(pages[1], 0, pages[1].getHeight())
|
||||
const images: string[][] = []
|
||||
|
||||
for (const bild of bilder) {
|
||||
let badge: string[];
|
||||
let image: string = "";
|
||||
|
||||
if (bild.uid) {
|
||||
image = `<img src="${fileURLToPath(new URL(`../../../../persistent/images/${bilder[0].uid}.webp`, import.meta.url))}" width="${(pages[2].getHeight() - 120) / 3.1}" />`
|
||||
} else if (bild.data) {
|
||||
image = `<img data="${bild.data}" width="${(pages[2].getWidth() - 120) / 3.1}" height="180" />`
|
||||
}
|
||||
|
||||
if (images.length > 0) {
|
||||
let badge = images[images.length - 1]
|
||||
if (badge.length == 3) {
|
||||
badge = [image]
|
||||
images.push(badge)
|
||||
} else {
|
||||
badge.push(image)
|
||||
}
|
||||
} else {
|
||||
badge = [image]
|
||||
images.push(badge)
|
||||
}
|
||||
}
|
||||
|
||||
const layoutPage3 = xml2pdf(`<layout height="${pages[2].getHeight()}" width="${pages[2].getWidth()}" marginTop="150" marginLeft="60" marginRight="60">
|
||||
${images.map(badge => `<flex direction="row" justify="space-between" width="${pages[2].getWidth() - 120}" height="180" marginTop="15">${badge.join("")}</flex>`).join("")}
|
||||
</layout>`, { "default": font })
|
||||
|
||||
layout.draw(pages[0], 0, pages[0].getHeight())
|
||||
layoutPage2.draw(pages[1], 0, pages[1].getHeight())
|
||||
layoutPage3.draw(pages[2], 0, pages[2].getHeight())
|
||||
|
||||
// const containerWidth = width - marginX;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user