parent
557cc26f28
commit
4617f2c5bd
@ -1,14 +1,42 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import pdf_converter from "html-pdf";
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is responsible for all things pdf creation.
|
* This class is responsible for all things pdf creation.
|
||||||
* This uses the html templates from src/templates.
|
* This uses the html templates from src/templates.
|
||||||
*/
|
*/
|
||||||
export class PdFCreator {
|
export class PdfCreator {
|
||||||
private templateDir = path.join(__dirname, '/templates');
|
private templateDir = path.join(__dirname, '/templates');
|
||||||
|
|
||||||
public generateSponsoringContract() {
|
public async generateSponsoringContract(): Promise<any> {
|
||||||
const template = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
|
const template = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
|
||||||
|
let pdf = await pdf_converter.create(template, { format: "A5", orientation: "landscape" });
|
||||||
|
return await this.toBuffer(pdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Promise wrapper function that resolves the toBuffer promise for pdf generation.
|
||||||
|
* @param pdf The pdf object that shall be turned into a buffer.
|
||||||
|
*/
|
||||||
|
public async toBuffer(pdf): Promise<any> {
|
||||||
|
let promise = await new Promise((resolve, reject) => {
|
||||||
|
pdf.toBuffer(function (err, buffer) {
|
||||||
|
resolve(buffer);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return await promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Promise wrapper function that resolves the toStream promise for pdf generation.
|
||||||
|
* @param pdf The pdf object that shall be turned into a stream.
|
||||||
|
*/
|
||||||
|
public async toStream(pdf): Promise<any> {
|
||||||
|
let promise = await new Promise((resolve, reject) => {
|
||||||
|
pdf.toStream(function (err, stream) {
|
||||||
|
resolve(stream);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return await promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user