web窗口打印

ASP.NET应用程序中,常常需要在浏览网页的同时,对网页中的内容进行打印。通过JavaScript打印方法和WebBrowser组件可以这病Web窗体的打印功能。

 

一、             打印Web窗本

    protected void Page_Load(object sender, EventArgs e)

    {

        string path = Server.MapPath(@"App_Data/TextFile.txt");

        StreamReader reader = new StreamReader(path, System.Text.Encoding.Default);

        lblTitle.Text = reader.ReadLine();

        lblContext.Text = reader.ReadToEnd();

        reader.Close();

    }

    protected void btnPrint_Click(object sender, EventArgs e)

    {

        Response.Write("<script>window.print()</script>");

    }

 

二、             利用WebBrowser实现打印

WebBrowserIE内置的浏览器组件,无须用户下载。它的优点是客户端能独立打印目标文档,减轻服务器负荷;缺点是源文档的分析操作复杂,并且源文档的打印内容要有约束。

 

<body style="text-align: center">

        <form id="Form1" runat="server">

            <table>

                <tr>

                    <td style="width: 466px; background-color: #ffffff; text-align: center;">

                        <asp:Label ID="Label1" runat="server" Font-Size=" 12pt " Font-Bold="True" ForeColor="Blue"></asp:Label>

                      </td></tr>

                    <tr><td style="font-size: 9pt ; width: 466px; text-indent: 8pt ; text-align: left; height: 380px;">

                        <asp:Label ID="Label2" runat="server" Font-Size=" 9pt " Height="376px" Width="430px" BorderColor="#8080FF" BorderWidth="1px" ForeColor="#404040"></asp:Label>

                      </td>

                </tr>

                <tr>

                    <td style="text-align: center; width: 466px; height: 46px;">

                <object id="WebBrowser" height="0" width="0" classid="CLSID: 8856F 961 -340A -11D0-A96B -00C 04FD 705A 2">

                </object>

                <asp:Panel ID="panel1" runat="server" Width="460px" Height="12px">

                <input onclick="document.all.WebBrowser.ExecWB(6,1);" type="button" value="打印" id="Button1" >

                <input onclick="document.all.WebBrowser.ExecWB(6,6);" type="button" value="直接打印" />

                <input onclick="document.all.WebBrowser.ExecWB(8,1);" type="button" value="页面设置" />

                <input onclick="document.all.WebBrowser.ExecWB(7,1);" type="button" value="打印预览" id="Button4" />

                <input type="button" value="关闭窗口" onclick="javascript:window.close()" />

                    </asp:Panel></td>

                </tr>

            </table>

            </form>

</body>

 

 

    protected void Page_Load(object sender, EventArgs e)

    {

        string path = Server.MapPath(@"App_Data/TextFile.txt");

        StreamReader reader = new StreamReader(path, System.Text.Encoding.Default);

        lblTitle.Text = reader.ReadLine();

        lblContext.Text = reader.ReadToEnd();

        reader.Close();

    }

    protected void btnPrint_Click(object sender, EventArgs e)

    {

        Response.Write("<script>window.print()</script>");

    }

Document.all.WebBrowser.ExecWB(6,1)

表示打印

Document.all.WebBrowser.ExecWB(6,6)

表示直接打印

Document.all.WebBrowser.ExecWB(7,1)

表示打印预览

Document.all.WebBrowser.ExecWB(8,1)

表示页面设置

 

 

Document.all.WebBrowser.ExecWB(1,1)

表示打开

Document.all.WebBrowser.ExecWB(2,1)

表示关闭现在所有的IE窗口,并打开一个新窗口。

Document.all.WebBrowser.ExecWB(4,1)

表示保存网页

Document.all.WebBrowser.ExecWB(0,1)

表示查看钢页属性

Document.all.WebBrowser.ExecWB(15,1)

表示撤消

Document.all.WebBrowser.ExecWB(17,1)

表示全选

Document.all.WebBrowser.ExecWB(22,1)

表示刷新

Document.all.WebBrowser.ExecWB(45,1)

表示关闭窗体无提示。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值