html bs架构调用客户端打印机用客户端及客户端局域网打印机打印,使用ScriptX.cab控件

<html>  
  <head>  
  <style   type="text/css"   media="print">  
  DIV.d1   {   DISPLAY:   none}  
  P{page-break-after:   always}    
  </style>  
  </head>  
  <body>  
  打印可以这样实现(仅作简单示例):  
  <p></p>  
  也可把那个CAB文件下载到本地服务器再引用它.<br>  
   
  在这里加入打印内容及控制分页............  
  <div   class="d1">  
  <OBJECT   id="MyPrinter"   style="DISPLAY:   none"   codeBase="smsx1.cab#Version=5,60,0,360"    
   
  classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"   viewastext>  
  </OBJECT>  
  <SCRIPT   defer>  
  function   window.onload()   {  
  MyPrinter.printing.header   =   ""  
  MyPrinter.printing.footer   =   ""  
  MyPrinter.printing.portrait=true  
  MyPrinter.printing.leftMargin   =5  
  MyPrinter.printing.topMargin   =   5  
  MyPrinter.printing.rightMargin   =   1  
  MyPrinter.printing.bottomMargin   =   1  
  //MyPrinter.printing.paperSize="Letter"  
  }  
  </SCRIPT>  
  <input   style="WIDTH:   87px;   HEIGHT:   24px"   onclick='document.execCommand("print")'   type="button"    
   
  value="打印...">  
  <!--     <INPUT   onclick=MyPrinter.printing.Print(false)   type=button   value=打印本頁>   -->  
  <input   name="button"   type="button"   onClick="MyPrinter.printing.PageSetup()"   value="页面设置">  
  <INPUT   onclick="MyPrinter.printing.Preview()"   type="button"   value="打印预览">   <br>  
   
  </div>  
  </body>  
  </html>

<OBJECT
这段代码用来加载cab文件,clsid和codebase必须要和你下载的cab中的信息对应,否则组件会加载错误,解压下载的cab文件,然后找到扩展名是.inf的文件,然后打开,就能看到了

其他打印相关:

1,直接调用
 
 <a href="javascript:window.print();">打印</a>  


2,WebBrowser

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>

 <BODY>
     <OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>   
    <input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开>  
   <input name=Button onClick=document.all.WebBrowser.ExecWB(2,1) type=button value=关闭所有>  
    <input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为>   
  <input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印>  
   <input name=Button onClick=document.all.WebBrowser.ExecWB(6,6) type=button value=直接打印>  
   <input name=Button onClick=document.all.WebBrowser.ExecWB(7,1) type=button value=打印预览>  
  <input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置>  
   <input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性>  
  <input name=Button onClick=document.all.WebBrowser.ExecWB(17,1) type=button value=全选>  
   <input name=Button onClick=document.all.WebBrowser.ExecWB(22,1) type=button value=刷新>  
   <input name=Button onClick=document.all.WebBrowser.ExecWB(45,1) type=button value=关闭>  
 </BODY>
</HTML>


3,打印

<html>  
   
  <head>  
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">  
  <meta   name="GENERATOR"   content="Microsoft   FrontPage   4.0">  
  <meta   name="ProgId"   content="FrontPage.Editor.Document">  
  <script   language="JavaScript">  
   
  function   doPrintSetup(){  
  //打印设置  
  WB.ExecWB(8,1)  
  }  
   
  function   doPrint()   {  
  //打印  
  newwin=window.print();  
  }  
   
  </script>  
   
  <title>New   Page   1</title>  
  <base   target="main">  
  </head>  
   
  <body>  
  <p   align="right">  
  <OBJECT   classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2   height=0   id=WB   width=0></OBJECT>  
  <input   type="button"   name="Close"   value="关闭窗口"   onclick="javascript:parent.close();">  
  <input   type="button"   name="PrintSetup"   value="打印设置"   onclick="doPrintSetup();">    
  <input   type="button"   name="Print"   value="打印"   onclick="doPrint();">    
  </body>  
   
  </html> 


4,超链接打印
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <script language=javascript>   
function doPrint() {   
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();   
}   
</script> 
 </HEAD>

 <BODY>
  <a href="javascript:;" onClick="doPrint()">打印</a>
 </BODY>
</HTML>


黑色头发:http://heisetoufa.iteye.com/

你可能感兴趣的:(html)