web窗口打印
来源:互联网 发布:吉林省水利造价软件 编辑:程序博客网 时间:2024/05/18 09:58
在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实现打印
WebBrowser是IE内置的浏览器组件,无须用户下载。它的优点是客户端能独立打印目标文档,减轻服务器负荷;缺点是源文档的分析操作复杂,并且源文档的打印内容要有约束。
<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="
</td></tr>
<tr><td style="font-size:
<asp:Label ID="Label2" runat="server" Font-Size="
</td>
</tr>
<tr>
<td style="text-align: center; width: 466px; height: 46px;">
<object id="WebBrowser" height="0" width="0" classid="CLSID:
</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) | 表示关闭窗体无提示。 |
- web窗口打印
- web打印
- WEB打印
- web打印
- Web打印
- WEB打印
- web打印
- Web打印
- web打印
- WEB打印
- web打印
- web打印
- web打印
- Web打印
- WEB打印
- Web打印
- WEB打印
- web打印
- RHEL的系统服务
- DLL调用异常
- OTL 4.0,无量纲SQL指令(2010.4.24更新)
- WALMART 即将关闭其 DRM 服务器
- 对"继承和初始化"的思考
- web窗口打印
- 查找有多少个串口
- 衰落的摩托罗拉:中国的IT黄埔
- 操作DataGridView中的DataTable
- linux 下TFTP 配置
- 天学会Project 2007 当当网链接地址
- java泛型解析01
- 托管C++ 是非托管代码和托管代码之间的一个桥梁
- Hibernate中outer-join与lazy关键字的使用