ff-admin-server/src/helpers/pdfExport.ts

35 lines
924 B
TypeScript
Raw Normal View History

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");
}
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));
}
}