当前位置: 代码迷 >> ASP >> ASP打印解决办法
  详细解决方案

ASP打印解决办法

热度:259   发布时间:2012-02-25 10:01:48.0
ASP打印
我直接把数据库的东西输出在页面上,通过IE打印,但是每次都要调整页边距,很是麻烦,请问高手有没有写在代码里,直接打印即可得方法?
谢谢!

------解决方案--------------------
HTML code

<script language="JavaScript" type="text/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 RegWsh = new ActiveXObject("WScript.Shell")
        
        hkey_key="margin_left"    //定义左边距
        RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"0.25")   //0.25为边距,根据实际修改
        
        hkey_key="margin_right"   //定义右边距
        RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"0.25")
        
        
      }catch(e){
      }
  }  
</script>

------解决方案--------------------
我们公司是用ReYoPrint,给你个调用的例子
<OBJECT ID="ReYoPrint" CLASSID="CLSID:5C230622-45E5-4e3c-893C-3BFDDC4DB5E4" codebase="../ReYoPrint.cab" height="0" width="0"></OBJECT>
<script>
ReYoPrint.MarginLeft=4; //设置左边边距
ReYoPrint.MarginRight=2; //设置右边边距
ReYoPrint.MarginTop=4; //设置上边边距
ReYoPrint.MarginBottom=2; //设置下边边距
ReYoPrint.CopyCount=1; //打印份数
ReYoPrint.PageHeader=""; //页眉
ReYoPrint.PageFooter=""; //页脚
ReYoPrint.IsLandScape=0; //把页面设置为横向1
//ReYoPrint.ContentURL="http://www.interdrp.com/print.html";
</script>
<div class="only_print_view">
<input type="button" id="btnPrint" value="打印预览" onClick="ReYoPrint.PrintPreview()">
<input type="button" id="btnPrint" value="打印文件" onClick="ReYoPrint.Print()">
<input type="button" id="btnPrint" value="直接打印" onClick="ReYoPrint.PrintDirect()">
------解决方案--------------------
还能去除页眉页脚
HTML code

<HTML><HEAD>   
  <script   language="VBScript">   
  dim   hkey_root,hkey_path,hkey_key   
  hkey_root="HKEY_CURRENT_USER"   
  hkey_path="\Software\Microsoft\Internet   Explorer\PageSetup"   
  '//设置网页打印的页眉页脚为空   
  function   pagesetup_null()   
          on   error   resume   next   
          Set   RegWsh   =   CreateObject("WScript.Shell")   
          hkey_key="\header"           
          RegWsh.RegWrite   hkey_root+hkey_path+hkey_key,""   
          hkey_key="\footer"   
          RegWsh.RegWrite   hkey_root+hkey_path+hkey_key,""   
  end   function   
  '//设置网页打印的页眉页脚为默认值   
  function   pagesetup_default()   
          on   error   resume   next   
          Set   RegWsh   =   CreateObject("WScript.Shell")   
          hkey_key="\header"           
          RegWsh.RegWrite   hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P"   
          hkey_key="\footer"   
          RegWsh.RegWrite   hkey_root+hkey_path+hkey_key,"&u&b&d"   
  end   function   
  </script>   
  </HEAD>   
    
  <BODY   onload="pagesetup_null()"   onbeforeunload="pagesetup_default()">   
  </BODY></HTML>

------解决方案--------------------
上面是用onload和onunload事件来执行这两个操作,还可以用按钮操作
HTML code

<HTML><HEAD>   
  <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   RegWsh   =   new   ActiveXObject("WScript.Shell")   
          hkey_key="header"           
          RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")   
          hkey_key="footer"   
          RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")   
  }catch(e){}   
  }   
  //设置网页打印的页眉页脚为默认值   
  function   pagesetup_default(){   
  try{   
          var   RegWsh   =   new   ActiveXObject("WScript.Shell")   
          hkey_key="header"           
          RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P")   
          hkey_key="footer"   
          RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d")   
  }catch(e){}   
  }   
  </script>   
  </HEAD>   
    
  <BODY><br/><br/><br/><br/><br/><br/><p   align=center>   
  <input   type="button"   value="清空页码"   onclick=pagesetup_null()>   
  <input   type="button"   value="恢复页码"   onclick=pagesetup_default()><br>   
  </p></BODY></HTML> 
  相关解决方案