一个关于页面的打印问题 我需要打印页面,但是打印出来的页面太大了,我如何去缩小页面,想把所有的打印出来,打印机会去掉多余的请问题大家遇到过这种问题吗?请教一个方法. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用div来控制,可以设置页面哪些部分需要打印,那些部分不需要打印,参考:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebPrint.aspx.cs" Inherits="_Default" %><HTML> <HEAD> <title>打印行程单</title> <style type="text/css"> .STYLE1 { COLOR: #ff0000 } </style> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <!--media=print 这个属性可以在打印时有效,只需要将不想打印部分的class设置为Noprint就可以了--> <style media="print"> .Noprint { DISPLAY: none } .PageNext { PAGE-BREAK-AFTER: always } </style><script>//按钮事件 var directPrint = function(){ pagesetup_null(); var div =document.getElementById("wsp"); var div1 =document.getElementById("pt"); div.style.display=""; div1.style.display="none"; document.all.WebBrowser.ExecWB(6,6); div.style.display="none"; div1.style.display=""; }//设置网页打印的页眉页脚为空function pagesetup_null(){ var hkey_root,hkey_path,hkey_key; hkey_root="HKEY_CURRENT_USER" hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; try{ var RegWsh = new ActiveXObject("WScript.Shell"); hkey_key="header"; RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,""); hkey_key="footer"; RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,""); }catch(e){} } </script> </HEAD> <body> <form id="WebPrint" method="post" runat="server"> <table class="Noprint" width="98%" border="0" height=25 bordercolor="#000033" style="WIDTH:780px;"> <tr > <td width=90 style="font-size: 9pt">电子客票号码:</td> <td width=90 style="font-size: 9pt"><asp:DropDownList ID="TextBox1" Height=25 width=125 runat="server" AutoPostBack="True" OnSelectedIndexChanged="TextBox1_SelectedIndexChanged"></asp:DropDownList></td> <td> <asp:Button ID="LinkButton1" runat="server" OnClick="LinkButton1_Click1" Width=90 style="font-size: 9pt" Text="创建行程单信息" ></asp:Button> <asp:Button ID="LinkButton2" runat="server" OnClick="LinkButton2_Click1" Width=80 style="font-size: 9pt" Text="作废行程单" OnClientClick="return confirm('您确定要取消行程单吗?')"></asp:Button> <input type=button name="打印" value="打印" style="font-size: 9pt; min-width:15px; min-height:10px" onclick="directPrint()" id="Button1" /> </td> <td> <OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0> </OBJECT> </td> <td width=200></td> </tr> </table> <div><table id="Table4" width="730" height="280" border="0" cellpadding="5" cellspacing="5"> <tr> <td width="931"> <div id="Div1" style="Z-INDEX:101;font-size:12pt;LEFT:441px;WIDTH:272px; POSITION:absolute; TOP:11px; HEIGHT:20px" align="left" ><%=Vise%></div> <div id="Div6" style="Z-INDEX:110;font-size:12pt;LEFT:80px; WIDTH:136px; POSITION:absolute; TOP:223px; HEIGHT:20px" align="left"><%=Tel%></div> <table ID="Table5" width="98%" cellpadding="3" align="LEFT" style="Z-INDEX:100;font-size:12pt; LEFT:53px; WIDTH:690px; POSITION:absolute; TOP:65px"> <%=Text%> </table> <div id="Div7" style="Z-INDEX:113; LEFT:80px; font-size:12pt; font-family:WIDTH:120px; POSITION:absolute; TOP:248px; HEIGHT:20px; width: 119px;" align="left"><%=Code%></div> <div id="Div8" style="Z-INDEX:112; LEFT:272px;font-size:12pt; WIDTH:296px; POSITION:absolute; TOP:254px; HEIGHT:20px" align="left"><%=Company%></div> <div id="Div9" align="left" style="Z-INDEX:106; font-size:12pt;LEFT:690px; WIDTH:55px; POSITION:absolute; TOP:228px; HEIGHT:20px"><%=Safety%></div> <div id="Div10" align="left" style="Z-INDEX:101;font-size:12pt; LEFT:201px; WIDTH:203px; POSITION:absolute; TOP:11px; HEIGHT:20px;"><%=Idec%></div> <div id="Div11" style="Z-INDEX:111; LEFT:256px; font-size:12pt;WIDTH:67px; POSITION:absolute; TOP:221px; HEIGHT:19px" align="left"><%=Verify%></div> <div id="Div12" align="left" style="Z-INDEX:101;font-size:12pt; LEFT:21px; WIDTH:183px; POSITION:absolute; TOP:11px; HEIGHT:20px"><%=Name%></div> <div id="Div13" align="left" style="Z-INDEX:107;font-size:12pt; LEFT:416px; WIDTH:200px; POSITION:absolute; TOP:221px; HEIGHT:20px"><%=Kep%></div> <div id="Div14" align="left" style="Z-INDEX:108; font-size:12pt;LEFT:632px; WIDTH:96px; POSITION:absolute; TOP:254px; HEIGHT:20px"><%=Date%></div> <table width="98%" align="center" style="Z-INDEX:103; LEFT:164px; WIDTH:556px; POSITION:absolute; TOP:197px; HEIGHT:21px" ID="Table6"> <tr> <td width="100" align="left" height="20" style="font-size: 12pt"><%=Fare%></td> <td width="100" height="20" align="left" style="font-size: 12pt"><%=JcFare%></td> <td height="20" width="108" align="left" style="font-size: 12pt"><%=RyFare%></td> <td height="20" width="94" align="left" style="font-size: 12pt"><%=Rest%></td> <td height="20" width="132" align="left" style="font-size: 12pt"><%=Total%></td> </tr> </table> <div id="Div15" align="center" style="Z-INDEX:105; LEFT:21px; WIDTH:88px;font-size: 12pt; POSITION:absolute; TOP:39px; HEIGHT:20px"><%=Pnr%></div> <div id="Div16" style="Z-INDEX:113; LEFT:79px; font-size:12pt;WIDTH:120px; POSITION:absolute; TOP:267px; HEIGHT:20px" align="left"><%=Hxh%></div></td> </tr> </table> </div> </form> </body></HTML> 请问大家有没有更加简单的方法,我页面布局是用css+div做的我调试了很久都没有出来效果,我做这个是给别人打印用的 <script type="text/javascript" language="javascript"> function doPrint() { bdhtml=window.document.body.innerHTML; sprnstr="<!--startprint-->"; eprnstr="<!--endprint-->"; prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); window.document.body.innerHTML=prnhtml; window.print(); } </script> 放在开始打印的地方<!--startprint--> ······结束的地方<!--endprint--> 创建WEB项目时,本地系统与IIS方式--图片路径的差异?? ASP.NET 远程发布失败 无法创建网站。您没有被授权执行当前的操作。 用户控件不正常 怎么编写这样的留言板? ###如何获取web按钮事件?谁知道相关插件### asp.net 选择文件夹 一個比較難的問題,DataGrid中實現固定列 20分送人!!!!! 能UrlRewrit吗 用asp.net的 美化url 怎样把页面中html控件中的值取出来? 使用ITextSharp生成PDF,如果定位套打的文字位置? [求助] Profile是不是只能用MemberShip的数据库啊?
<HTML>
<HEAD>
<title>打印行程单</title>
<style type="text/css"> .STYLE1 { COLOR: #ff0000 } </style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print 这个属性可以在打印时有效,只需要将不想打印部分的class设置为Noprint就可以了-->
<style media="print"> .Noprint { DISPLAY: none }
.PageNext { PAGE-BREAK-AFTER: always } </style><script>//按钮事件
var directPrint = function(){
pagesetup_null();
var div =document.getElementById("wsp");
var div1 =document.getElementById("pt");
div.style.display="";
div1.style.display="none";
document.all.WebBrowser.ExecWB(6,6);
div.style.display="none";
div1.style.display="";
}//设置网页打印的页眉页脚为空
function pagesetup_null(){
var hkey_root,hkey_path,hkey_key;
hkey_root="HKEY_CURRENT_USER"
hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
try{
var RegWsh = new ActiveXObject("WScript.Shell");
hkey_key="header";
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");
hkey_key="footer";
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");
}catch(e){}
}
</script>
</HEAD>
<body>
<form id="WebPrint" method="post" runat="server">
<table class="Noprint" width="98%" border="0" height=25 bordercolor="#000033" style="WIDTH:780px;">
<tr >
<td width=90 style="font-size: 9pt">电子客票号码:</td>
<td width=90 style="font-size: 9pt"><asp:DropDownList ID="TextBox1" Height=25 width=125 runat="server" AutoPostBack="True" OnSelectedIndexChanged="TextBox1_SelectedIndexChanged"></asp:DropDownList></td>
<td> <asp:Button ID="LinkButton1" runat="server" OnClick="LinkButton1_Click1" Width=90 style="font-size: 9pt" Text="创建行程单信息" ></asp:Button>
<asp:Button ID="LinkButton2" runat="server" OnClick="LinkButton2_Click1" Width=80 style="font-size: 9pt" Text="作废行程单" OnClientClick="return confirm('您确定要取消行程单吗?')"></asp:Button>
<input type=button name="打印" value="打印" style="font-size: 9pt; min-width:15px; min-height:10px" onclick="directPrint()" id="Button1" />
</td>
<td>
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
</td>
<td width=200></td>
</tr>
</table>
<div>
<table id="Table4" width="730" height="280" border="0" cellpadding="5" cellspacing="5">
<tr>
<td width="931">
<div id="Div1" style="Z-INDEX:101;font-size:12pt;LEFT:441px;WIDTH:272px; POSITION:absolute; TOP:11px; HEIGHT:20px"
align="left" ><%=Vise%></div>
<div id="Div6" style="Z-INDEX:110;font-size:12pt;LEFT:80px; WIDTH:136px; POSITION:absolute; TOP:223px; HEIGHT:20px"
align="left"><%=Tel%></div>
<table ID="Table5" width="98%" cellpadding="3" align="LEFT" style="Z-INDEX:100;font-size:12pt; LEFT:53px; WIDTH:690px; POSITION:absolute; TOP:65px">
<%=Text%> </table> <div id="Div7" style="Z-INDEX:113; LEFT:80px; font-size:12pt; font-family:WIDTH:120px; POSITION:absolute; TOP:248px; HEIGHT:20px; width: 119px;"
align="left"><%=Code%></div>
<div id="Div8" style="Z-INDEX:112; LEFT:272px;font-size:12pt; WIDTH:296px; POSITION:absolute; TOP:254px; HEIGHT:20px"
align="left"><%=Company%></div>
<div id="Div9" align="left" style="Z-INDEX:106; font-size:12pt;LEFT:690px; WIDTH:55px; POSITION:absolute; TOP:228px; HEIGHT:20px"><%=Safety%></div>
<div id="Div10" align="left" style="Z-INDEX:101;font-size:12pt; LEFT:201px; WIDTH:203px; POSITION:absolute; TOP:11px; HEIGHT:20px;"><%=Idec%></div>
<div id="Div11" style="Z-INDEX:111; LEFT:256px; font-size:12pt;WIDTH:67px; POSITION:absolute; TOP:221px; HEIGHT:19px"
align="left"><%=Verify%></div>
<div id="Div12" align="left" style="Z-INDEX:101;font-size:12pt; LEFT:21px; WIDTH:183px; POSITION:absolute; TOP:11px; HEIGHT:20px"><%=Name%></div>
<div id="Div13" align="left" style="Z-INDEX:107;font-size:12pt; LEFT:416px; WIDTH:200px; POSITION:absolute; TOP:221px; HEIGHT:20px"><%=Kep%></div>
<div id="Div14" align="left" style="Z-INDEX:108; font-size:12pt;LEFT:632px; WIDTH:96px; POSITION:absolute; TOP:254px; HEIGHT:20px"><%=Date%></div>
<table width="98%" align="center" style="Z-INDEX:103; LEFT:164px; WIDTH:556px; POSITION:absolute; TOP:197px; HEIGHT:21px"
ID="Table6">
<tr>
<td width="100" align="left" height="20" style="font-size: 12pt"><%=Fare%></td>
<td width="100" height="20" align="left" style="font-size: 12pt"><%=JcFare%></td>
<td height="20" width="108" align="left" style="font-size: 12pt"><%=RyFare%></td>
<td height="20" width="94" align="left" style="font-size: 12pt"><%=Rest%></td>
<td height="20" width="132" align="left" style="font-size: 12pt"><%=Total%></td>
</tr>
</table>
<div id="Div15" align="center" style="Z-INDEX:105; LEFT:21px; WIDTH:88px;font-size: 12pt; POSITION:absolute; TOP:39px; HEIGHT:20px"><%=Pnr%></div>
<div id="Div16" style="Z-INDEX:113; LEFT:79px; font-size:12pt;WIDTH:120px; POSITION:absolute; TOP:267px; HEIGHT:20px"
align="left"><%=Hxh%></div></td>
</tr>
</table>
</div>
</form>
</body>
</HTML>
我调试了很久都没有出来效果,我做这个是给别人打印用的
function doPrint() {
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
</script>
放在开始打印的地方<!--startprint-->
······结束的地方<!--endprint-->