Using the code shown below, the PDF document seems not to be a valid PDF format. The browser displays the message, "Failed to load PDF document." If I save the download to a file and open it in Adobe Reader, it gives the message, "There was an error opening this document."
I can open and download the document manually within Google Docs. So, it is a valid PDF document.
I'm using C#, ASP.NET, and Google.Documents.
// get the document to download
Feed<Document> 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( );
}
UPDATE: Resolved. code shown below.