zoukankan      html  css  js  c++  java
  • 如何用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();
                    }

                }

      

  • 相关阅读:
    [转]Hello ActiveMQ
    Access中合并两张表为一张表
    infragistics ultraGrid单元格、行只读
    (转)c#中对"Crossthread operation not valid"错误的处理办法
    [LintCode] String Homomorphism Review
    [LintCode] Longest Increasing Continuous Subsequence Review
    [LintCode] Longest Increasing Continuous subsequence II Review
    [LintCode] Coins in a Line II Review
    标准的SQL的解析顺序
    SQLServer 存储过程 SET NOCOUNT { ON | OFF } 的使用(转载)
  • 原文地址:https://www.cnblogs.com/oula_king/p/2353593.html
Copyright © 2011-2022 走看看