marcbachmann / node-html-pdf

This repo isn't maintained anymore as phantomjs got dreprecated a long time ago. Please migrate to headless chrome/puppeteer.
MIT License
3.56k stars 544 forks source link

Typescript return #543

Open Eliminator92 opened 4 years ago

Eliminator92 commented 4 years ago

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?

FelipeArisi commented 2 years ago

I have the same issue Is there any update?