render protocol by template

This commit is contained in:
Julian Krauser 2024-10-18 15:23:51 +02:00
parent da219eb5f4
commit 58213923e5
8 changed files with 950 additions and 3 deletions

34
src/helpers/pdfExport.ts Normal file
View file

@ -0,0 +1,34 @@
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");
}
static async renderFile({ template, title, data }: { template: string; title: string; data: any }) {
let document = {
html: this.getTemplate(template),
data,
path: process.cwd() + `/export/${title}.pdf`,
};
await pdf.create(document, options(title));
}
}