Skip to content

Instantly share code, notes, and snippets.

@fsojitra
Created March 17, 2018 06:56
Show Gist options
  • Save fsojitra/b894d780bbc23f0563949519a75fb684 to your computer and use it in GitHub Desktop.
Save fsojitra/b894d780bbc23f0563949519a75fb684 to your computer and use it in GitHub Desktop.
var express = require('express');
var fs = require('fs');
var pdf = require('html-pdf');
var app = express();
app.get('/',function(req, res){
var html = fs.readFileSync('./test/test.html', 'utf8');
var options = { format: 'Letter' };
pdf.create(html, options).toFile('./test.pdf', function(err, resp) {
if (err) {
return console.log(err);
res.send('data');
}else{
console.log(resp);
var file= 'F:/Nodehtmltopdf/test.pdf';
var data = fs.readFileSync(file);
// console.log(data);
// resp.contentType("application/pdf");
res.send(data);
}
});
/* pdf.create(html, options).toFile('./test.pdf', function(err, res) {
if (err){
return console.log(err);
} else {
console.log(res); // { filename: '/app/businesscard.pdf' }
// res.send(res);
}
});*/
})
app.listen(3000, function(){
console.log('Server started on port 3000');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment