实现页面打印(javascript)

本文介绍了一种使用 ASP.NET 实现网页打印功能的方法,通过内嵌 ActiveX 控件 WebBrowser 实现了打印、打印预览等功能,并展示了具体的 HTML 和参数配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="NeiMengDispatchOrder.WebForm1" %>
<HTML>
    
<HEAD>
        
<title>看看</title>
        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        
<!--media=print 这个属性可以在打印时有效-->
        
<style media="print">
.Noprint 
{ DISPLAY: none }
.PageNext 
{ PAGE-BREAK-AFTER: always }
        
</style>
        
<style>
.tdp 
{ BORDER-RIGHT: #ffffff 0px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid }
.tabp 
{ BORDER-RIGHT: #000000 2px solid; BORDER-TOP: #000000 2px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid }
.NOPRINT 
{ FONT-SIZE: 9pt; FONT-FAMILY: "宋体" }
        
</style>
    
</HEAD>
    
<body>
        
<center class="Noprint">
            
<p>
                
<OBJECT id="WebBrowser" height="0" width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"
                    VIEWASTEXT
>
                    
<PARAM NAME="ExtentX" VALUE="26">
                    
<PARAM NAME="ExtentY" VALUE="26">
                    
<PARAM NAME="ViewMode" VALUE="0">
                    
<PARAM NAME="Offline" VALUE="0">
                    
<PARAM NAME="Silent" VALUE="0">
                    
<PARAM NAME="RegisterAsBrowser" VALUE="0">
                    
<PARAM NAME="RegisterAsDropTarget" VALUE="1">
                    
<PARAM NAME="AutoArrange" VALUE="0">
                    
<PARAM NAME="NoClientEdge" VALUE="0">
                    
<PARAM NAME="AlignLeft" VALUE="0">
                    
<PARAM NAME="NoWebView" VALUE="0">
                    
<PARAM NAME="HideFileNames" VALUE="0">
                    
<PARAM NAME="SingleClick" VALUE="0">
                    
<PARAM NAME="SingleSelection" VALUE="0">
                    
<PARAM NAME="NoFolders" VALUE="0">
                    
<PARAM NAME="Transparent" VALUE="0">
                    
<PARAM NAME="ViewID" VALUE="{0057D0E0-3573-11CF-AE69-08002B2E1262}">
                    
                
</OBJECT>
                
<input type="button" value="打印" onclick="document.all.WebBrowser.ExecWB(6,1)"> <input type="button" value="直接打印" onclick="document.all.WebBrowser.ExecWB(6,6)">
                
<input type="button" value="页面设置" onclick="document.all.WebBrowser.ExecWB(8,1)">
            
</p>
            
<p>
                
<input type="button" value="打印预览" onclick="document.all.WebBrowser.ExecWB(7,1)">
                
<br>
            
</p>
            
<hr align="center" width="90%" size="1" noshade>
        
</center>
        
        
<form id="Form1" method="post" runat="server">
        
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
            
<tr>
                
<td colspan="3" class="tdp">第1页</td>
            
</tr>
            
<tr>
                
<td width="29%" class="tdp">&nbsp;
                    
<asp:Label id="Label2" runat="server">Label</asp:Label></td>
                
<td width="28%" class="tdp">&nbsp;
                    
<asp:Label id="Label1" runat="server">Label</asp:Label></td>
                
<td width="43%" class="tdp">&nbsp;
                    
<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList></td>
            
</tr>
            
<tr>
                
<td colspan="3" class="tdp">&nbsp;</td>
            
</tr>
            
<tr>
                
<td colspan="3" class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        
<tr>
                            
<td width="50%" class="tdp"><p>这样的报表</p>
                                
<p>对一般的要求就够了。</p>
                            
</td>
                            
<td>&nbsp;</td>
                        
</tr>
                    
</table>
                
</td>
            
</tr>
        
</table>
        
</form>
        
        
<hr align="center" width="90%" size="1" noshade class="NOPRINT">
        
<!--分页-->
        
<div class="PageNext"></div>
        
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
            
<tr>
                
<td class="tdp">第2页</td>
            
</tr>
            
<tr>
                
<td class="tdp">看到分页了吧</td>
            
</tr>
            
<tr>
                
<td class="tdp">&nbsp;</td>
            
</tr>
            
<tr>
                
<td class="tdp">&nbsp;</td>
            
</tr>
            
<tr>
                
<td class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        
<tr>
                            
<td width="50%" class="tdp"><p>这样的报表</p>
                                
<p>对一般的要求就够了。</p>
                            
</td>
                            
<td>&nbsp;</td>
                        
</tr>
                    
</table>
                
</td>
            
</tr>
        
</table>
    
</body>
</HTML>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值