title: Error while opening PDF
body: <p>I am getting "<strong>Failed to load PDF document</strong>" in Chrome and "<strong>The file is damaged and could not be repaired</strong>" in IE for few files.</p>
  
  <p>The code is as below:</p>
  
  <p>PDFSteramer:</p>
  
  <pre><code>if (pdf != null)
  {
      Response.ContentType = "application/PDF";
      Response.AddHeader("Content-Type", "application/pdf");
      Response.AddHeader("Content-Disposition", "inline");
  
      pdf.Renderer.Render(pdf, Response.OutputStream);
  
      Response.Flush();
  }
  </code></pre>
  
  <p>And in Render class:</p>
  
  <pre><code>using (FileStream fs = new FileStream(this._ParentDocument.Document.FullName, FileMode.Open, FileAccess.Read))
  {                                                 
      byte[] buffer = new byte[bufferSize];
  
      fs.Read(buffer, 0, bufferSize);
  
      using (StringReader reader = new StringReader(System.Text.ASCIIEncoding.ASCII.GetString(buffer)))
      {                        
          Decoder decoder = new UuDecoder(stream, "");
  
          string data;
  
          while ((data = reader.ReadLine()) != null)
          {
              decoder.DecodeLine(data);
          }
      }
  }
  </code></pre>
  
  <p>and in DecodeLine is as below:</p>
  
  <pre><code>public override bool DecodeLine(string line)
  {
      try
      {                                                             
          byte[] data = Encoding.UTF8.GetBytes(line);
          //byte[] data = uuDecode(line);
  
          outStream.Write(data, 0, data.Length);                  
      }
      catch (Exception ex)
      {
      }
      return false;
  }    
  </code></pre>
  
  <p>Below is what it throws in Firefox:</p>
  
  <p><a href="https://i.stack.imgur.com/kPN6e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kPN6e.png" alt="enter image description here"></a></p>
  
  <p>And on Adobe reader:</p>
  
  <p><a href="https://i.stack.imgur.com/qsFwx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qsFwx.png" alt="enter image description here"></a></p>