WebBrowser设置打印页眉页眉和页边距
2008-03-27 10:21
411 查看
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);
}
原以为修改注册表,用服务器端代码会好些,测试也达到了预想效果,但是忽略了一个问题:只能修改服务器端注册码。。。
失败!
由于是套打,格式要求很严格,页眉页脚、页边距等等等等。
在网上找到下列代码,做适当修改后基本上能满足要求了,但是由于是用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);
}
原以为修改注册表,用服务器端代码会好些,测试也达到了预想效果,但是忽略了一个问题:只能修改服务器端注册码。。。
失败!
相关文章推荐
- WebBrowser设置打印页眉页眉和页边距
- js 设置网页打印的页眉页脚和页边距
- JavaScript实现网页打印,可设置页眉、页脚、页边距
- js 设置网页打印的页眉页脚和页边距
- WebBrowser 打印设置,打印预览,去页眉和页脚
- 去除IE浏览器打印时的页眉页脚及设置页边距--简单实用,一次性解决
- JAVASCRIPT实现网页打印,可设置页眉、页脚、页边距
- js页面设置与打印(页眉页脚,页边距设置)
- 网页打印样式设置(页眉,页脚,页边距)
- WebBrowser 打印设置,打印预览,去页眉和页脚
- 利用vbs脚本设置IE的打印页眉页脚信息(zhuan)
- 打印html时设置去掉页眉页脚 简单一行代码搞定(记录一下)
- RDLC打印或导出Word的 分页设置 页边距和页面大小
- JS 网页打印 页边距 页眉页脚
- WebBrowser OBJECT 打印设置
- Silverlight打印全套解决方案--支持打印预览、页面设置(横向纵向,页边距,纸张大小、字体大小)、自动分页和多页连续打印
- 如何使用WebBrowser控件打印格式化的XML文档,并以编程方式任意设置打印方向(C#完整示例)
- javascript打印设置页眉页脚
- 如何在 Internet Explorer 中以编程方式更改 Internet Explorer 和 WebBrowser 控件的打印设置
- 【LaTeX入门】06、设置页芯、页边距、页眉、页脚