PDF Datenblatt Bilder
This commit is contained in:
@@ -2,6 +2,7 @@ import { PDFPage, PDFFont, rgb, RGB, PDFImage } from 'pdf-lib';
|
||||
import { PDFElement, Size } from './PDFElement.js';
|
||||
import { Margin, Padding } from './Layout.js';
|
||||
import * as fs from "fs"
|
||||
import { getS3File } from '#lib/s3.js';
|
||||
|
||||
export interface ImageOptions {
|
||||
margin?: Margin,
|
||||
@@ -43,11 +44,12 @@ export class Image extends PDFElement {
|
||||
async draw(page: PDFPage, x: number, y: number) {
|
||||
let embed: PDFImage;
|
||||
if (this.options.src) {
|
||||
if (!fs.existsSync(this.options.src)) {
|
||||
const img = await getS3File("ibc-images", this.options.src);
|
||||
|
||||
if (!img) {
|
||||
return;
|
||||
}
|
||||
|
||||
const img = fs.readFileSync(this.options.src)
|
||||
if (this.options.src.split(".").pop() === "png") {
|
||||
embed = await page.doc.embedPng(img)
|
||||
} else {
|
||||
|
||||
@@ -364,7 +364,7 @@ export async function pdfDatenblattVerbrauchsausweisGewerbe(ausweis: Verbrauchsa
|
||||
}
|
||||
|
||||
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}" />`
|
||||
image = `<img src="${bild.uid}.jpg" width="${(pages[2].getWidth() - 120) / 3.1}" height="${(pages[2].getHeight() - marginY * 2) / 4}" />`
|
||||
}
|
||||
|
||||
if (images.length > 0) {
|
||||
|
||||
@@ -307,7 +307,7 @@ export async function pdfDatenblattVerbrauchsausweisWohnen(ausweis: Verbrauchsau
|
||||
}
|
||||
|
||||
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}" />`
|
||||
image = `<img src="${bild.uid}.jpg" width="${(pages[2].getWidth() - 120) / 3.1}" height="${(pages[2].getHeight() - marginY * 2) / 4}" />`
|
||||
}
|
||||
|
||||
if (images.length > 0) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import { addText } from "./utils/text.js";
|
||||
import { addAnsichtsausweisLabel, addDatumGEG } from "./utils/helpers.js";
|
||||
import { PERSISTENT_DIR } from "#lib/server/constants.js";
|
||||
import { fileURLToPath } from "url";
|
||||
import { getS3File } from "#lib/s3.js";
|
||||
|
||||
|
||||
export async function pdfVerbrauchsausweisGewerbe(ausweis: VerbrauchsausweisGewerbeClient, aufnahme: AufnahmeClient, objekt: ObjektClient, bilder: BildClient[], user: BenutzerClient) {
|
||||
@@ -142,10 +143,9 @@ export async function pdfVerbrauchsausweisGewerbe(ausweis: VerbrauchsausweisGewe
|
||||
const bild = bilder && bilder.find(image => image.kategorie === Enums.BilderKategorie.Gebaeude);
|
||||
|
||||
if (bild) {
|
||||
const path = `${PERSISTENT_DIR}/images/${bild.uid}.jpg`;
|
||||
const file = await getS3File("ibc-images", `${bild.uid}.jpg`);
|
||||
|
||||
if (fs.existsSync(path)) {
|
||||
const file = fs.readFileSync(fileURLToPath(new URL(path, import.meta.url)))
|
||||
if (file) {
|
||||
let image: PDFImage;
|
||||
image = await pdf.embedJpg(file)
|
||||
pages[0].drawImage(image, {
|
||||
|
||||
@@ -10,6 +10,7 @@ import { addText } from "./utils/text.js";
|
||||
import { addAnsichtsausweisLabel, addDatumGEG } from "./utils/helpers.js";
|
||||
import { fileURLToPath } from "url";
|
||||
import { PERSISTENT_DIR } from "#lib/server/constants.js";
|
||||
import { getS3File } from "#lib/s3.js";
|
||||
|
||||
/* -------------------------------- Pdf Tools ------------------------------- */
|
||||
|
||||
@@ -148,10 +149,9 @@ export async function pdfVerbrauchsausweisWohnen(ausweis: VerbrauchsausweisWohne
|
||||
const bild = bilder && bilder.find(image => image.kategorie === Enums.BilderKategorie.Gebaeude);
|
||||
|
||||
if (bild) {
|
||||
const path = `${PERSISTENT_DIR}/images/${bild.uid}.jpg`;
|
||||
const file = await getS3File("ibc-images", `${bild.uid}.jpg`);
|
||||
|
||||
if (fs.existsSync(path)) {
|
||||
const file = fs.readFileSync(fileURLToPath(new URL(path, import.meta.url)))
|
||||
if (file) {
|
||||
let image: PDFImage;
|
||||
image = await pdf.embedJpg(file)
|
||||
pages[0].drawImage(image, {
|
||||
|
||||
Reference in New Issue
Block a user