How to create PDF from dynamic html in express js

Viewed 79

I am trying to render ejs into html and then generate a pdf from html. that works fine and pdf generated but the user input data that saved in report.ejs not found in report.pdf( is empty ).

this is app.js code:



app.post('/report', function (req, res){
    
    
     const data = ({
         partnername:req.body.partnername,
        Requirement1:req.body.Requirement1,
        Requirement2:req.body.Requirement2,
     });
    



    

  ejs.renderFile(path.join(__dirname,'views', 'pages', 'report.ejs'), 
 data, {}, function(err, str) {
    if (err) return res.send(err);

    // str now contains your rendered html
    pdf.create(str).toFile("report2.pdf", function(err, data) {
      if (err) return res.send(err);
     console.log(res);
      res.send("File created successfully");
      
      
       

    });
  });

when user press save in report.ejs should send data that user inputs to database and create pdf file using the code above.

current and status are based on user inputs: report pdf

0 Answers
Related