java 打印功能实现

来源:互联网 发布:w7怎么连接网络 编辑:程序博客网 时间:2024/06/04 18:29

最近公司的OA系统刚起步,正在编写一些通用的功能代码,工具类,打印当然必不可少,最简单的实现方式当然是window.print();然而这个方法会打印出当前页面的所有内容 ,后来我选择用@media print来控制打印内容的样式;具体代码如下:

  1. <style>     
  2. @media print {   
  3. .noprint {    
  4. display: none    
  5. }   
  6. }   
  7. </style>  

 

  1. 这里是打需要打印的内容.<span class="noprint">只显示不打印</span>  
  2. <div class="noprint" >  
  3. <table style="margin:0 auto;width:500px;">  
  4.     <tr align="center" ><td>  
  5.       <object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0"  
  6.                     width="0">  
  7.       </object>  
  8.   <input type="button" value="打印" onclick="document.all.WebBrowser.ExecWB(6,1)">  
  9.   <input type="button" value="页面设置" onclick="document.all.WebBrowser.ExecWB(8,1)">  
  10. <input type="button" value="直接打印" onclick="document.all.WebBrowser.ExecWB(6,6)">  
  11.   <input type="button" value="打印预览" onclick="document.all.WebBrowser.ExecWB(7,1)">  
  12.     </td></tr>  
  13. </table></div>  

0 0
原创粉丝点击