title: display pdf as stream in webbrowser control
body: <p>In my windows application, I want to read a pdf file and using byte[] I want to convert it into a text file.</p>
  
  <p>I am able to do this but while displaying the content of text file in webbrowser control it is displaying some encoded data.</p>
  
  <p>How can I display the actual data in pdf. Below is my code</p>
  
  <p>Convert pdf to text file</p>
  
  <pre><code>byte[] bytes = System.IO.File.ReadAllBytes(OpenPdfDialog.FileName);
  string byteString = Encoding.Default.GetString(bytes);
  System.IO.File.WriteAllText(@"E:\file.txt", byteString );
  </code></pre>
  
  <p>Displaying content to webbrowser control</p>
  
  <pre><code> byte[] bytes = System.IO.File.ReadAllBytes(@"E:\path.txt");
   MemoryStream ms = new MemoryStream(bytes2);
   ms.Write(bytes, 0, bytes.Length);
   ms.Position = 0;
   webBrowser1.DocumentStream = ms;
  </code></pre>
  
  <p>OR</p>
  
  <p>Reading the file as stream and displaying the stream in the webbrowser control also displaying the encoded data</p>
  
  <pre><code>FileStream to_strem = new FileStream(OpenPdfDialog.FileName, FileMode.Open);
  webBrowser1.DocumentStream = to_strem ;
  </code></pre>
  
  <p>Ultimately I want to display the pdf's content into webbrowser control without loading the pdf file.</p>