2024-10-18 15:23:51 +02:00
|
|
|
import { readFileSync } from "fs";
|
|
|
|
import pdf, { Options } from "pdf-creator-node";
|
|
|
|
|
|
|
|
var options = (title: string = "pdf-export Mitgliederverwaltung"): Options => ({
|
|
|
|
format: "A4",
|
|
|
|
orientation: "portrait",
|
|
|
|
border: "10mm",
|
|
|
|
header: {
|
|
|
|
height: "10mm",
|
|
|
|
contents: `<h1 style="text-align: center;">${title}</h1>`,
|
|
|
|
},
|
|
|
|
footer: {
|
|
|
|
height: "5mm",
|
|
|
|
contents: {
|
|
|
|
default: '<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export abstract class PdfExport {
|
|
|
|
static getTemplate(template: string) {
|
|
|
|
return readFileSync(process.cwd() + "/src/templates/" + template, "utf8");
|
|
|
|
}
|
|
|
|
|
2024-10-19 16:24:41 +02:00
|
|
|
static async renderFile({
|
|
|
|
template,
|
|
|
|
title,
|
|
|
|
filename,
|
|
|
|
data,
|
|
|
|
}: {
|
|
|
|
template: string;
|
|
|
|
title: string;
|
|
|
|
filename: string;
|
|
|
|
data: any;
|
|
|
|
}) {
|
2024-10-18 15:23:51 +02:00
|
|
|
let document = {
|
|
|
|
html: this.getTemplate(template),
|
|
|
|
data,
|
2024-10-19 16:24:41 +02:00
|
|
|
path: process.cwd() + `/export/${filename}.pdf`,
|
2024-10-18 15:23:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
await pdf.create(document, options(title));
|
|
|
|
}
|
|
|
|
}
|