求助:asp控制web页面打印
最近在做一个快递单打印功能.在网上找了很多关于web页面打印控制的代码,都无法实现我想要的效果.
以下是采用网上的一段控制页眉,页脚,和边距的代码,使用针式打印机打印效果不怎么好,老是无法控制位置,有时能准确的印在快递单上.
请教各位高手,帮帮忙,万分感谢.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><%=Title%></title>
<script defer>
function SetPrintSettings(){
try
{
factory.printing.SetMarginMeasure(2) //measure margins in inches
factory.SetPageRange(false, 1, 3) // need pages from 1 to 3
factory.printing.printer = "HP DeskJet 870C"
factory.printing.copies = 2
factory.printing.collate = true
factory.printing.paperSize = "A4" //A3在这里修改
factory.printing.paperSource = "Manual feed"
// -- basic features
factory.printing.header = ""
factory.printing.footer = ""
factory.printing.portrait = false
factory.printing.leftMargin = 32
factory.printing.topMargin = 6.5
factory.printing.rightMargin = 0
factory.printing.bottomMargin = 0
}
catch(e)
{}
}
</script>
<script language="javascript">
/*
function printsetup(){
factory.execwb(8,1);
}
function printpreview(){
factory.execwb(7,1);
}
*/
function printit(){
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;
SetPrintSettings();
window.print();
}
</script>
</head>
<body>
<object classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=factory name=factory width=0></object>
<!--startprint-->
<table border="0" width="750px" cellspacing="0" cellpadding="0">
<tr>
<td height="40px" colspan="4"></td>
</tr>
<tr>
<td width="170px"></td>
<td valign="top">
<table align="left" border="0" width="250" cellspacing="0" cellpadding="2" style="font-size:12.5pt;font-family: 宋体">
<tr>
<td height="30px"> <%=SupContactName%></td>
</tr>
<tr>
<td height="12px" valign="top"></td>
</tr>
<tr>
<td height="45px" valign="top" style="line-hieght:130%;"> <%=SupAddress%></td>
</tr>
<tr>
<td height="30px"> <%=SupCompanyName%></td>
</tr>
<tr>
<td height="40px"> <%=SupTelephone%></td>
</tr>
</table>
</td>
<td width="90px"></td>
<td valign="top">
<table align="left" border="0" width="100%" cellspacing="0" cellpadding="2" style="font-size:12.5pt;font-family: 宋体">
<tr>
<td height="30px"> <%=DeliverContactName%></td>
</tr>
<tr>
<td height="12px" valign="top"></td>
</tr>
<tr>
<td height="45px" valign="top" style="line-hieght:130%;"> <%=DeliverAddress%></td>
</tr>
<tr>
<td height="30px"> <%=DeliverCompanyName%>(电话:<%=DeliverTelephone%>)</td>
</tr>
<tr>
<td height="40px"> <%=DeliverTelephone%></td>
</tr>
</table>
</td>
</tr>
</table>
<!--endprint-->
<table align="center" border="0" width="200" cellspacing="0" cellpadding="0">
<tr>
<td align="center" height="60"><img src="../Images/print.jpg" align="absmiddle" style="cursor:hand;" onClick="printit();"></td>
</tr>
</table>
</body>
</html>