一、
1、在web页面上按照打印要求布置好页面
2、打印函数:
<script language="javascript">
function print()
{
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();
window.close();
}
</script>
3、将需要打印的部分用函数中sprnstr和eprnstr所定义的字符串包含
4、调用print函数进行打印
二、使用MSDN上的一种方法可以打印多页自定义报表,具体查看
http://www.microsoft.com/china/MSDN/library/WebServices/ASP.NET/UsingASP.NETtoCreateMulti-PageCustomReports.mspx?mfr=true
另:从ms新闻组中摘录:
使用WebBrowser控件打印Web页面时指定默认打印机,请参考下述代码:
<OBJECT id="WSNetwork" style="DISPLAY: none" classid="CLSID:F935DC26-1CF0-11D0-ADB9-00C04FD58A0B" VIEWASTEXT></OBJECT>
<OBJECT id="WebBrowser1" height="0" width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" VIEWASTEXT></OBJECT>
function Print()
{
var strCurrentPrinter = "\\\\Hu\\HuPrint";
var strDefaultPrinter = "Smart Print";
WSNetwork.SetDefaultPrinter(strCurrentPrinter);
WebBrowser1.ExecWB(6,6);
window.setTimeout("window.opener = null;window.close();",1500);
}