I am trying to download a pdf without prompt using the pdf which is already present under mocked test data. And I am able to do the above task using the below code.But when I try to open the downloaded pdf I am getting 'Failed to load pdf document' what am I missing here.Kindly help.
fs.readFile('./src/test-data/service/print/notes.pdf', function(error, content) {
if (error) {
res.writeHead(500);
res.end();
}
else {
res.writeHead(200, {
'Content-Type': 'application/pdf',
'Content-Disposition': 'attachment; filename=notes.pdf'
});
res.end(content, 'utf-8');
}
});