How to send a pdf file from Node/Express app to the browser
You have to pipe from Readable Stream to Writable stream not the other way around:
var file = fs.createReadStream('./public/modules/datacollectors/output.pdf');
var stat = fs.statSync('./public/modules/datacollectors/output.pdf');
res.setHeader('Content-Length', stat.size);
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', 'attachment; filename=quote.pdf');
file.pipe(res);
Also you are setting encoding in wrong way, pass an object with encoding if needed.
how to convert a buffer to pdf on front end
On the frontend, you can create ObjectURL that can be downloaded using
const url = window.URL.createObjectURL(new Blob([this.props.resumePDF]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'yourcoolpdf.pdf');
document.body.appendChild(link);
link.click();
Related Topics
How to Restrict Past Dates in Html5 Input Type Date
Onclick Button Get from Database and Display on a Input Field Live
How to Save .Xlsx Data to File as a Blob
Show Virtual Keyboard on Mobile Phones in JavaScript
Angular 4: How to Read Content of Text File With Httpclient
React Wait Until Set State in the Same Function
React Native Flatlist With Clickable Items
How to Hide the Address Bar on Iphone
Remove the Default Browser Header and Footer When Printing HTML
Loading Screen Gets Stuck While Processing Http Request
How to Include External JavaScript Library in Reactjs
How to Save Binary Buffer to Png File in Nodejs
How to Add Node Module to Angular Project If Is Not Schematics Enabled
Amount of All Goals of One Team (From Json)
How to Change Color of Button on Press in React Native