Protocol Error - html-pdf-node npm package

Viewed 323

Using the htm-pdf-node package here. It gives the following error when I am trying to pass the data to it

Error: Protocol error (Page.navigate): Invalid parameters Failed to deserialize params.url - BINDINGS: mandatory field missing at position 49.

The code I am using is

import htmlPdf from 'html-pdf-node';
let option ={ format:"A4",path:"../BoilerplateTemplate"};
htmlPdf.generatePdf(boilerTemp(req.body.Name,req.body.RollNumber,req.body.CollegeName,req.body.Branch,req.body.Batch,req.body.ExperimentNo,req.body.Aim,req.body.Theory,req.body.Procedure,req.body.Apparatus,req.body.Observation,req.body.Conclusion),option)
             .then(pdfBuffer=> console.log(pdfBuffer))
     .catch(error=>console.log(error)); 

The boilerTemp() function has arguments

(Name,RollNumber,CollegeName,Branch,Batch,ExperimentNo,Aim,Theory,Procedure,Apparatus,Observation,Conclusion)

1 Answers

According to the doc the first parameter of generatePdf() should be a file object.

file <Object> File object should have one of the following properties:

  • url <string> Any public url of the PDF.
  • content <string> HTML file content of the PDF.

Are you sure your boilerTemp() function returns that object ?

EDIT with code in comment

The code of boilerTemp() should be like this :

const page = ({ Name,RollNumber,CollegeName,Branch,Batch,ExperimentNo,Aim,Theory,Procedure,Apparatus,Observation,Conclusion }) => {
  let content = ` html template document `;
  return { content };
}

export default page; 

I changed the parameters with only one object. Like this you can call boilerTemp() in a simpler way.

htmlPdf.generatePdf(boilerTemp(req.body),option);
Related