Verbesserungen

This commit is contained in:
Moritz Utcke
2025-03-09 06:34:01 -03:00
parent c3c7fd313f
commit a1e5945d73
14 changed files with 144 additions and 136 deletions

View File

@@ -4,7 +4,7 @@ import * as fs from "fs"
import { PDFDocument, rgb, StandardFonts, TextAlignment } from "pdf-lib";
import { xml2pdf } from "./elements/xml2pdf.js";
import moment from "moment";
import { Heizungsstatus } from "#lib/server/prisma.js";
import { Enums, Heizungsstatus } from "#lib/server/prisma.js";
import { endEnergieVerbrauchVerbrauchsausweisGewerbe_2016 } from "#lib/Berechnungen/VerbrauchsausweisGewerbe/VerbrauchsausweisGewerbe_2016.js";
import { fileURLToPath } from "url";
import { copyPage } from "./utils/copyPage.js";
@@ -355,37 +355,41 @@ export async function pdfDatenblattVerbrauchsausweisGewerbe(ausweis: Verbrauchsa
const images: string[][] = []
for (const bild of bilder) {
let badge: string[];
let image: string = "";
if (bild.uid) {
image = `<img src="${fileURLToPath(new URL(`${PERSISTENT_DIR}/images/${bilder[0].uid}.jpg`, 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 {
for (const bild of bilder) {
let badge: string[];
let image: string = "";
if (bild.kategorie === Enums.BilderKategorie.Gebaeude) {
continue;
}
if (bild.uid) {
image = `<img src="${fileURLToPath(new URL(`${PERSISTENT_DIR}/images/${bild.uid}.jpg`, import.meta.url))}" width="${(pages[2].getWidth() - 120) / 3.1}" height="${(pages[2].getHeight() - marginY * 2) / 4}" />`
} 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="${(pages[2].getHeight() - marginY * 2) / 4}" marginTop="15">${badge.join("")}</flex>`).join("")}
</layout>`, { "default": font })
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())
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;