WEB打印

来源:互联网 发布:python .t tranpose 编辑:程序博客网 时间:2024/05/21 06:12

循环打印div中的内容:
<input type="button" onClick="javascript:printpage('myDiv');" value="打印">
流程:
从数据库中取出记录-》放入aspx页面的一个Div中打印
例子:
在aspx中定义一个DIV,如:
<div id="myDiv">  
     <table border="0"  width="100%">
         <tr>
         <td>
        <table align="center" border="0" cellpadding="5" cellspacing="1"
            width="100%" class="test">
          <tr bgcolor="#CDD9F1" align="center">
            <td height="22" colspan="2" valign="middle">凭证</td>
          </tr>
        </table>
         </td>
    </tr>
    </table>
</div>
在apsx中定义一个按钮,按下事件触发
printpage('myDiv);
Printpage方法如下(javascript):
function printpage(myDiv){
   var newstr = document.all.item(myDiv).innerHTML;
   var oldstr = document.body.innerHTML;
   document.body.innerHTML = newstr;
   window.print();
   document.body.innerHTML = oldstr;
   return false;
}

******************************************************************************************************
<script  language="JavaScript"> 
var HKEY_Root,HKEY_Path,HKEY_Key;
HKEY_Root="HKEY_CURRENT_USER";
HKEY_Path="//Software//Microsoft//Internet Explorer//PageSetup//";
//设置网页打印的页眉页脚为空
function PageSetup_Null()
{
 try
 {
         var Wsh=new ActiveXObject("WScript.Shell");
  HKEY_Key="header";
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
  HKEY_Key="footer";
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
 }
 catch(e){}
}
//设置网页打印的页眉页脚为默认值
function  PageSetup_Default()

 try
 {
  var Wsh=new ActiveXObject("WScript.Shell");
  HKEY_Key="header";
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P");
  HKEY_Key="footer";
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");
 }
 catch(e){}
}
</script>
<input type="button" value="清空页码" onclick=PageSetup_Null()>
<input type="button" value="恢复页码" onclick=PageSetup_Default()>