pofider / phantom-html-to-pdf

Highly scalable html to pdf conversion using phantom workers
MIT License
159 stars 33 forks source link

Specify output file path? #74

Closed mcrowder65 closed 7 years ago

mcrowder65 commented 7 years ago

I'm not finding anywhere in the documentation or the code where I can specify the output path?

bjrmatos commented 7 years ago

hi! there is no output path option because this package returns an object with an stream in it, you can save the PDF to a file using the following code:

var fs = require('fs')
var conversion = require("phantom-html-to-pdf")();
conversion({ html: "<h1>Hello World</h1>" }, function(err, pdf) {
  var output = fs.createWriteStream('/path/to/your/output/directory/output.pdf')
  console.log(pdf.logs);
  console.log(pdf.numberOfPages);
  pdf.stream.pipe(output);
});
mcrowder65 commented 7 years ago

Perfect, thank you