Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require('http');
- var pdf = require('html-pdf');
- const PORT = 3000;
- var server = http.createServer((req, res) => {
- var html = 'https://nubecolectiva.com/uploads/archivo.pdf';
- // también:
- // var var html = 'C:\Downloads\archivo.pdf';
- // var var html = '<html><body> HTML Content ... </body></html>';
- pdf.create(html).toStream((err, stream) => {
- if (err) {
- console.error(err);
- res.status(500);
- res.end(JSON.stringify(err));
- return;
- }
- res.setHeader('Content-Type', 'application/pdf');
- res.setHeader('Content-Disposition', 'attachment; filename=archivo.pdf;');
- stream.pipe(res);
- });
- });
- server.listen(PORT, () => {
- console.log('Server listening on Port: %s', PORT);
- });
Add Comment
Please, Sign In to add comment