WebBrowser设置打印页眉页眉和页边距

webbrowser,居然被用作套打。。。。。。
由于是套打,格式要求很严格,页眉页脚、页边距等等等等。
在网上找到下列代码,做适当修改后基本上能满足要求了,但是由于是用JS修改注册码,因此和客户端的IE设置有很大关系,必须要求客户IE允许Activex。如果不允许,var Wsh=new ActiveXObject("WScript.Shell");将抛出一个异常。
<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 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,"");
  HKEY_Key="margin_bottom";
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0");
  HKEY_Key="margin_left";
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0");
  HKEY_Key="margin_right";
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0");
  HKEY_Key="margin_top";
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0");
 }
 catch(e){
    //alert(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>

第二种方法:直接在.cs文件中写方法。
    protected void Page_Load(object sender, EventArgs e)
    {
        //PageSetup("", "");
    }

    private void PageSetup(string header, string footer)
    {
        Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\PageSetup\\", true);
        rk.SetValue("header", header);
        rk.SetValue("footer", footer);
        rk.SetValue("margin_bottom", 0);
        rk.SetValue("margin_left", 0);
        rk.SetValue("margin_right", 0);
        rk.SetValue("margin_top", 0);

    }
原以为修改注册表,用服务器端代码会好些,测试也达到了预想效果,但是忽略了一个问题:只能修改服务器端注册码。。。
失败!
原文地址:https://www.cnblogs.com/lds85930/p/1124746.html