HI,
i have a problem with html-pdf and Typescript.
I wrote a service that looks for HTML ejs templates and then converts them into a PDF buffer. I want to send it by mail.
My code:
async pdf(name: any, data: any) {
const path = 'src/templates/mails/';
const header = await ejs.renderFile(path + 'header.ejs', data);
const body = await ejs.renderFile(path + name + '.ejs', data);
const footer = await ejs.renderFile(path + 'footer.ejs', data);
const html = header + body + footer;
let PDF = null;
pdf.create(html, { format: 'Letter' }).toBuffer(function (err: any, buffer: Buffer) {
console.log("first", buffer)
if (err) {
console.error(err);
}else {
console.log(Buffer.isBuffer(buffer)); //returns true
PDF = buffer;
}
});
console.log(PDF)// return undefine
return PDF;
}
HI, i have a problem with html-pdf and Typescript. I wrote a service that looks for HTML ejs templates and then converts them into a PDF buffer. I want to send it by mail.
My code:
async pdf(name: any, data: any) { const path = 'src/templates/mails/'; const header = await ejs.renderFile(path + 'header.ejs', data); const body = await ejs.renderFile(path + name + '.ejs', data); const footer = await ejs.renderFile(path + 'footer.ejs', data); const html = header + body + footer; let PDF = null; pdf.create(html, { format: 'Letter' }).toBuffer(function (err: any, buffer: Buffer) { console.log("first", buffer) if (err) { console.error(err); }else { console.log(Buffer.isBuffer(buffer)); //returns true PDF = buffer; } }); console.log(PDF)// return undefine return PDF; }
Where is my mistake?