title: How to download a PDF document from Google Docs and display it in the browser?
body: <p>Using the code shown below, the PDF document seems not to be a valid PDF format. The browser displays the message, "<strong>Failed to load PDF document.</strong>" If I save the download to a file and open it in Adobe Reader, it gives the message, "<strong>There was an error opening this document.</strong>" </p>
  
  <p>I can open and download the document manually within Google Docs. So, it is a valid PDF document.</p>
  
  <p>I'm using C#, ASP.NET, and Google.Documents.</p>
  
  <pre><code>        // get the document to download
          Feed&lt;Document&gt; feed = request.GetEverything( );
          foreach( Document entry in feed.Entries )
          {
              if( entry.AtomEntry.AlternateUri.ToString( ) == DocumentAltUri )
              {
                  document = entry;
                  break;
              }
          }
  
          using( Stream stream = request.Download( document, Document.DownloadType.pdf ) )
          {
              StreamReader reader = new StreamReader( stream );
              string content = reader.ReadToEnd( );
              reader.Close( );
  
              Response.ClearContent( );
              Response.ContentType = "application/pdf";
              Response.AddHeader( "Content-Length", content.Length.ToString( ) );
              Response.AddHeader( "Content-Disposition", "inline;" );
              Response.Write( content );
              Response.Flush( );
              Response.Close( );
              Response.End( );
          }
  </code></pre>
  
  <p><strong>UPDATE:</strong> Resolved. code shown below.</p>