Created
March 17, 2018 06:56
-
-
Save fsojitra/b894d780bbc23f0563949519a75fb684 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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