I know this is a bit old question but since I found a great module I thought of sharing it with everyone.
Module named Puppeteer that can make you run the Chrome in Headless mode and also interact with it via API. So now you can create a template and take the values of the placeholders of that template via POST call and generate the PDF on the fly, in server.
I created a small POC and here is the link to it: Demo-Puppeteer
Let me do a bit explanation here:
...........
const content = await compile(templateName, data);
/***
* Launched the headless chrome in memory.
*/
const browser = await puppeteer.launch();
/***
* Created a new page(tab)
*/
const page = await browser.newPage();
/***
* Set the content of the new page
*/
await page.setContent(content, { waitUntil: 'networkidle0' });
/***
* Telling chrome to emulate screen i.e how the page looks if
* it would have been rendered in the normal browser.
*/
await page.emulateMedia('screen');
const byteArray = await page.pdf({
format: "A4",
landscape: true,
scale: 1.29,
printBackground: true
});
const buffer = Buffer.from(byteArray, 'binary');
/**
* We don't need the acknowledgement of this call that is the
* reason we are not waiting for this call to return.
*/
browser.close();
return buffer;
.......
Now, this buffer is basically a binary data and you have to write it in a file using the file module of Node.
For further explanation please check out Exlpanation Link