javascript - Can't access a file by command while execution of code in Node JS -


i'm creating 1 file [html] @ run time node , converting pdf command line. html created pdf file created success empty.

i checked created html file contains data command line couldn't read guess. here code:

create html file:

var getpdf=function (html,filename,callback) {  fs.writefile("./pdf/"+filename+".html", html,'utf8', function(err) {      if(err) {          return callback(err,[]);      }      fs.readfile("./pdf/"+filename+".html","utf8", (err, data) => {            if (err) throw err;         console.log(data);     });      return callback(err,filename);   });  } 

create pdf after html created:

var html="<html><head><title>hello world</title></head><body><h1>hello     sarath!</h1></body></html>";   getpdf(html,'sarath',function (err, filename) {     if(err) {        console.log("error: "+err);        return false;      }      var cmd="xvfb-run wkhtmltopdf ./pdf/"+filename+" ./pdf/"+filename+".pdf";      console.log(cmd);      exec(cmd,function(err,stdout,stderr){         if(err) {            return console.log(err);;         }         console.log("pdf created!",stdout);      });   }); 

it coudln't find file cause missed extension

var html="<html><head><title>hello world</title></head><body><h1>hello     sarath!</h1></body></html>";   getpdf(html,'sarath',function (err, filename) {     if(err) {        console.log("error: "+err);        return false;      }      var cmd="xvfb-run wkhtmltopdf ./pdf/"+filename+".html ./pdf/"+filename+".pdf";      console.log(cmd);      exec(cmd,function(err,stdout,stderr){         if(err) {            return console.log(err);;         }         console.log("pdf created!",stdout);      });   }); 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -