0

PDF ファイルを含む応答を受け取りました

HttpWebResponse res = (HttpWebResponse)HttpWRequest.GetResponse();
Stream pdf = res.GetResponseStream();

この PDF をファイルに保存せずに Web ブラウザーで表示したい。どうすればそれができますか?

4

2 に答える 2

1

次のコードを使用していますが、正常に動作します。

public static void SendDataByteFileToClient(HttpContext context, byte[] data, string fileName, string contentType, bool clearHeaders = true)
        {

            if (clearHeaders)
            {
                context.Response.Clear();
                context.Response.ClearHeaders();
            }

            context.Response.BufferOutput = true;
            context.Response.ContentType = contentType;

            context.Response.AddHeader("Content-Disposition", "inline; filename=" + fileName);
            context.Response.AddHeader("Content-Length", data.Length.ToString());

            if (BrowserHelper.IsOfType(BrowserTypeEnum.IE) && BrowserHelper.Version < 9)
            {
                context.Response.Cache.SetCacheability(HttpCacheability.Private);
                context.Response.Cache.SetMaxAge(TimeSpan.FromMilliseconds(1));
            }
            else
            {
                context.Response.Cache.SetCacheability(HttpCacheability.NoCache);//IE set to not cache
                context.Response.Cache.SetNoStore();//Firefox/Chrome not to cache
                context.Response.Cache.SetExpires(DateTime.UtcNow); //for safe measure expire it immediately
            }

            if (data.Length > 0)
            {
                context.Response.BinaryWrite(data);
            }

            context.Response.End();
        }
于 2013-10-24T16:02:42.067 に答える