如何用C# 输出pdf文件流在页面上显示

1、首先客户端需要安装Adobe Reader这个东西

2、前台html代码如下 :

     <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="100%" height="1050"

        border="0">
        <param name="_Version" value="65539">
        <param name="_ExtentX" value="20108">
        <param name="_ExtentY" value="10866">
        <param name="_StockProps" value="0">
        <param name="SRC" value="<%=_pdf %>">

    </object 

   这个_pdf变量是后台的一个全局变量_pdf = "Handler.ashx?Id=" + _Id + "&Name=" + _name;

3、在Hander中抓取pdf ,_arr为byte流(byte[])

 var _arr = service.GetDocumentContents(_Id); 


            if (!Equals(null, _arr) && _arr.Length > 0)
            {
                try
                {
                    context.Response.ContentType = "application/pdf";
                    context.Response.AddHeader("Content-Disposition""attachment;  filename=" + HttpUtility.UrlEncode(_name, System.Text.Encoding.UTF8));
                    context.Response.BinaryWrite(_arr);
                    context.Response.Flush();
                    context.Response.End();
                }
                catch 
                {
                    context.Response.Close();
                }
                finally
                {
                    context.Response.Close();
                }

            }

  

原文地址:https://www.cnblogs.com/oula_king/p/2353593.html