diff --git a/src/PdfCreator.ts b/src/PdfCreator.ts index 8e547b2..2345c8c 100644 --- a/src/PdfCreator.ts +++ b/src/PdfCreator.ts @@ -1,6 +1,8 @@ import fs from "fs"; import pdf_converter from "html-pdf"; import path from 'path'; +import { Stream } from 'stream'; + /** * This class is responsible for all things pdf creation. * 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 { content: any; @@ -27,9 +33,9 @@ export class Pdf { /** * Promise wrapper function that resolves the toBuffer promise for pdf generation. */ - public async toBuffer(): Promise { - let promise = await new Promise((resolve, reject) => { - this.content.toBuffer(function (err, buffer) { + public async toBuffer(): Promise { + let promise = await new Promise((resolve, reject) => { + this.content.toBuffer(function (err, buffer: Buffer) { resolve(buffer); }); }); @@ -39,9 +45,9 @@ export class Pdf { /** * Promise wrapper function that resolves the toStream promise for pdf generation. */ - public async toStream(): Promise { - let promise = await new Promise((resolve, reject) => { - this.content.toStream(function (err, stream) { + public async toStream(): Promise { + let promise = await new Promise((resolve, reject) => { + this.content.toStream(function (err, stream: Stream) { resolve(stream); }); });