【发布时间】:2012-03-05 18:30:17
【问题描述】:
使用下面显示的代码,PDF 文档似乎不是有效的 PDF 格式。浏览器显示消息“加载 PDF 文档失败。”如果我将下载保存到文件并在 Adobe Reader 中打开,它会显示消息“打开时出错这份文件。”
我可以在 Google 文档中手动打开和下载文档。因此,它是一个有效的 PDF 文档。
我正在使用 C#、ASP.NET 和 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( );
}
更新:已解决。代码如下。
【问题讨论】:
标签: asp.net google-docs