`
ch.net
  • 浏览: 112590 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

打印页面

阅读更多

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Print.aspx.cs" Inherits="Print" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script 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="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){}
  }
  // 打印预览
  function PrintPreview(){ 
     pagesetup_null();
     document.all.wb.execwb(7,1);
     return true;
   }
       
        function printsetup()
      {
          // 打印页面设置
            var wb = document.getElementById("wb");
          wb.execwb(8, 1);
      }
      
      function printpreview()
      {
          // 打印页面预览
          pagesetup_null();
            var wb = document.getElementById("wb");
            SetVisible("none");
          wb.execwb(7, 1);
            SetVisible("block");
      }

      function printit()
      {
          pagesetup_null();
            SetVisible("none");
            window.print();
          //wb.execwb(6, 6)
            SetVisible("block");           
      }
      
      function SetVisible(display)
      {
          document.getElementById("trPrint").style.display = display;
      }
   -->
  </script>
</head>
<body>
    <form id="form1" runat="server">
    <object id="wb" height="0" width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" name="wb" ></object>
    <div id="trPrint">
        <input onclick="javascript:printit()" type="button" value="打印" name="btnPrint" id="btnPrint" />
        <input onclick="javascript:printsetup();" type="button" value="打印页面设置" name="btnSetup" id="btnSetup" />
        <input onclick="javascript:printpreview();" type="button" value="打印预览" name="btnPreview" id="btnPreview"/>
        <input onclick="window.close()" type="button" value="关闭" />
    </div>
    </form>
</body>
</html>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics