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