im using html-pdf package node , need send file response. actual code on pdf.create
function
pdf.create(html, options).tostream((err, stream) => { if(err) throw err; stream.pipe(fs.createwritestream(__dirname + '/gen.pdf')); var file = fs.createreadstream(__dirname + '/gen.pdf'); //file.pipe(res); res.setheader('content-type', 'application/pdf'); res.setheader('content-disposition', 'attachment; filename="gen.pdf"'); res.sendfile(__dirname+'/gen.pdf'); });
why not stream directly response? example:
pdf.create(html, options).tostream((err, stream) => { if (err) throw err; res.setheader('content-type', 'application/pdf'); res.setheader('content-disposition', 'attachment; filename="gen.pdf"'); stream.pipe(res); });
Comments
Post a Comment