java套打

1:套打可能是以后软件开发可能会涉及到的功能,主要麻烦地方就是需要精确定位,光是打印发票还好,要是打印那种协议类型的特别麻烦,不仅长而且需要的数据多 ,定位麻烦。

2:而且大多数情况是需要去除页眉页脚的,一般使用的是activix来控制页眉页脚,以及边距的控制

3:然而activix操作注册列表是被ie浏览器安全控制所禁止的,我们需要将站点添加到信任站点中,并且在自定义级别中将有关activix使用都设为允许,就可以进行打印了

4:下面是网上找到的代码

var HKEY_Root, HKEY_Path, HKEY_Key;
HKEY_Root = "HKEY_CURRENT_USER";
HKEY_Path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
var head, foot, top, bottom, left, right;


//取得页面打印设置的原参数数据
function PageSetup_temp() {
try {
var Wsh = new ActiveXObject("WScript.Shell");
HKEY_Key = "header";
//取得页眉默认值
head = Wsh.RegRead(HKEY_Root + HKEY_Path + HKEY_Key);
HKEY_Key = "footer";
//取得页脚默认值
foot = Wsh.RegRead(HKEY_Root + HKEY_Path + HKEY_Key);
HKEY_Key = "margin_bottom";
//取得下页边距
bottom = Wsh.RegRead(HKEY_Root + HKEY_Path + HKEY_Key);
HKEY_Key = "margin_left";
//取得左页边距
left = Wsh.RegRead(HKEY_Root + HKEY_Path + HKEY_Key);
HKEY_Key = "margin_right";
//取得右页边距
right = Wsh.RegRead(HKEY_Root + HKEY_Path + HKEY_Key);
HKEY_Key = "margin_top";
//取得上页边距
top = Wsh.RegRead(HKEY_Root + HKEY_Path + HKEY_Key);
} catch(e) {
alert("不允许ActiveX控件"+e);
}
alert(left+":"+bottom+":"+top+":"+right);
}


//设置网页打印的页眉页脚和页边距
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";
//设置下页边距(0)
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0");
HKEY_Key = "margin_left";
//设置左页边距(0)
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0.1");
HKEY_Key = "margin_right";
//设置右页边距(0)
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0");
HKEY_Key = "margin_top";
//设置上页边距(8)
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0.7");
} catch(e) {
alert("不允许ActiveX控件22"+e.message);
}
}


//设置网页打印的页眉页脚和页边距为默认值
function PageSetup_Default() {
try {
var Wsh = new ActiveXObject("WScript.Shell");
HKEY_Key = "header";
HKEY_Key = "header";
//还原页眉
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, head);
HKEY_Key = "footer";
//还原页脚
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, foot);
HKEY_Key = "margin_bottom";
//还原下页边距
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, bottom);
HKEY_Key = "margin_left";
//还原左页边距
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, left);
HKEY_Key = "margin_right";
//还原右页边距
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, right);
HKEY_Key = "margin_top";
//还原上页边距
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, top);
} catch(e) {
alert("不允许ActiveX控件11");
}
}


posted @ 2014-03-12 14:14  小小架构师  阅读(861)  评论(0编辑  收藏  举报