I think you need to create an html template and then make your json in an html template.
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <table> <tr>Company</tr> {{info.Company}} <tr>Team</tr> {{info.Team}} </table> </body> </html>
Now in your js file you need to specify the path to your template, as well as create a folder for storing your file in pdf format.
var pdf = require('html-pdf'); var options = {format: 'Letter'}; exports.Topdf = function (req, res) { var info = { "Company": "ABC", "Team": "JsonNode", "Number of members": 4, "Time to finish": "1 day" } res.render('path to your tempalate', { info: info, }, function (err, HTML) { pdf.create(HTML, options).toFile('./downloads/employee.pdf', function (err, result) { if (err) { return res.status(400).send({ message: errorHandler.getErrorMessage(err) }); } }) }) }
Try with the hope that this will work.
source share