title: Downloaded .pdf files are corrupted when using expressjs
body: <p>I am working on <code>meanjs</code> application generated using <a href="https://github.com/DaftMonk/generator-angular-fullstack" rel="noreferrer">https://github.com/DaftMonk/generator-angular-fullstack</a>. I am trying to generate a .pdf file using <code>phantomjs</code> and download it to the browser.</p>
  
  <p>The issue is that the downloaded .pdf file always shows the blank pages regardless of the number of pages. The original file on server is not corrupt. When I investigated further, found that the downloaded file is always much larger than the original file on the disk. Also this issue happens only with .pdf files. Other file types are working fine.</p>
  
  <p>I've tried several methods like <code>res.redirect('http://localhost:9000/assets/exports/receipt.pdf');</code>, <code>res.download('client\\assets\\exports\\receipt.pdf')</code>,</p>
  
  <pre><code>var fileSystem = require('fs');
  var stat = fileSystem.statSync('client\\assets\\exports\\receipt.pdf');
  res.writeHead(200, {
                      'Content-Type': 'application/pdf',
                      'Content-Length': stat.size
                  });
  
  var readStream = fileSystem.createReadStream('client\\assets\\exports\\receipt.pdf');
  return readStream.pipe(res);
  </code></pre>
  
  <p>and even I've tried with <a href="https://github.com/expressjs/serve-static" rel="noreferrer">https://github.com/expressjs/serve-static</a>  with no changes in the result.</p>
  
  <p>I am new to <code>nodejs</code>. What is the best way to download a .pdf file to the browser?</p>
  
  <p><strong>Update:</strong>
  I am running this on a Windows 8.1 64bit Computer</p>