最近客户要求做一个打印功能,本想在直接用window.print();直接打印出来,感觉不是很满意。于是发现利用active控件打印还是不错。现将源码附上,以供以后项目参考。相信大家一家源码就明白了,相当简单,我在这里就不多废话了。
css控制打印区域代码如下所示:
<style>
@media print {
.noprint {
display: none
}
}
</style>
这里是打需要打印的内容.<span class="noprint">我只显示不打印哦,很神奇吧。哈哈</span>
<div class="noprint" >
<table style="margin:0 auto;width:500px;">
<tr align="center" ><td>
<object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0"
width="0">
</object>
<input type="button" value="打印" οnclick="document.all.WebBrowser.ExecWB(6,1)">
<input type="button" value="页面设置" οnclick="document.all.WebBrowser.ExecWB(8,1)">
<input type="button" value="直接打印" οnclick="document.all.WebBrowser.ExecWB(6,6)">
<input type="button" value="打印预览" οnclick="document.all.WebBrowser.ExecWB(7,1)">
</td></tr>
</table></div>