parent
7d5b5750ad
commit
3fb8be22b7
@ -1,6 +1,8 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import pdf_converter from "html-pdf";
|
import pdf_converter from "html-pdf";
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import { Stream } from 'stream';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
@ -17,6 +19,10 @@ export class PdfCreator {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is a wrapper for the pdf objects created by html-pdf.
|
||||||
|
* It offers typed conversion to Buffer and Stream.
|
||||||
|
*/
|
||||||
export class Pdf {
|
export class Pdf {
|
||||||
content: any;
|
content: any;
|
||||||
|
|
||||||
@ -27,9 +33,9 @@ export class Pdf {
|
|||||||
/**
|
/**
|
||||||
* Promise wrapper function that resolves the toBuffer promise for pdf generation.
|
* Promise wrapper function that resolves the toBuffer promise for pdf generation.
|
||||||
*/
|
*/
|
||||||
public async toBuffer(): Promise<any> {
|
public async toBuffer(): Promise<Buffer> {
|
||||||
let promise = await new Promise((resolve, reject) => {
|
let promise = await new Promise<Buffer>((resolve, reject) => {
|
||||||
this.content.toBuffer(function (err, buffer) {
|
this.content.toBuffer(function (err, buffer: Buffer) {
|
||||||
resolve(buffer);
|
resolve(buffer);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -39,9 +45,9 @@ export class Pdf {
|
|||||||
/**
|
/**
|
||||||
* Promise wrapper function that resolves the toStream promise for pdf generation.
|
* Promise wrapper function that resolves the toStream promise for pdf generation.
|
||||||
*/
|
*/
|
||||||
public async toStream(): Promise<any> {
|
public async toStream(): Promise<Stream> {
|
||||||
let promise = await new Promise((resolve, reject) => {
|
let promise = await new Promise<Stream>((resolve, reject) => {
|
||||||
this.content.toStream(function (err, stream) {
|
this.content.toStream(function (err, stream: Stream) {
|
||||||
resolve(stream);
|
resolve(stream);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user