Merge branch 'main' into #1-account-management
# Conflicts: # src/data-source.ts
This commit is contained in:
commit
273745f830
66 changed files with 3721 additions and 10 deletions
44
src/helpers/pdfExport.ts
Normal file
44
src/helpers/pdfExport.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
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,
|
||||
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));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue