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: `
${title}
`,
},
footer: {
height: "5mm",
contents: {
default: '{{page}}/{{pages}}',
},
},
});
export abstract class PdfExport {
static getTemplate(template: string) {
return readFileSync(process.cwd() + "/src/templates/" + template, "utf8");
}
static async renderFile({
template,
title,
filename,
data,
}: {
template: string;
title: string;
filename: string;
data: any;
}) {
let document = {
html: this.getTemplate(template),
data,
path: process.cwd() + `/export/${filename}.pdf`,
};
await pdf.create(document, options(title));
}
}