IE下使用js与自带ActiveX控制web打印
来源:互联网 发布:手机淘宝直通车怎么做 编辑:程序博客网 时间:2024/05/17 09:34
一.打印需求1.控制页眉页脚和上下左右的页边距
2.可选横向打印
3.跳过配置对话直接打印
二.环境与背景
1.浏览器版本:IE8
2.不能使用ScriptX
3.不能开发新ActiveX
三.实现
1.控制页眉页脚和页边距
2.横向打印
2.可选横向打印
3.跳过配置对话直接打印
二.环境与背景
1.浏览器版本:IE8
2.不能使用ScriptX
3.不能开发新ActiveX
三.实现
1.控制页眉页脚和页边距
使用ActiveX组件"WScript.Shell"对注册表进行访问修改,相当于修改了IE中的打印设置。
web_printer.js:
function JSActiveXPrinter(){this.header = null;this.footer = null;this.marginTop = null;this.marginBottom = null;this.marginLeft = null;this.marginRight = null;this.localHeader = null;this.localFooter = null;this.localMarginTop = null;this.localMarginBottom = null;this.localMarginLeft = null;this.localMarginRight = null;this.portrain = false;this.wsShell = new ActiveXObject("WScript.Shell");this.regPath = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";}JSActiveXPrinter.prototype.doPrint = function(){this.getLocalPageSetup();this.setPageSetup();window.print();this.recoverPageSetup();}JSActiveXPrinter.prototype.getLocalPageSetup = function(){//Get local page setup setting for recoverythis.localHeader = this.wsShell.RegRead(this.regPath + "header");this.localFooter = this.wsShell.RegRead(this.regPath + "footer");this.localMarginTop = this.wsShell.RegRead(this.regPath + "margin_top");this.localMarginBottom = this.wsShell.RegRead(this.regPath + "margin_bottom");this.localMarginLeft = this.wsShell.RegRead(this.regPath + "margin_left");this.localMarginRight = this.wsShell.RegRead(this.regPath + "margin_right");//Set defualt valuethis.header = this.localHeader;this.footer = this.localFooter;this.marginTop = this.localMarginTop;this.marginBottom = this.localMarginBottom;this.marginLeft = this.localMarginLeft;this.marginRight = this.localMarginRight;}JSActiveXPrinter.prototype.setPageSetup = function(){this.wsShell.RegWrite(this.regPath + "header", this.header);this.wsShell.RegWrite(this.regPath + "footer", this.footer);this.wsShell.RegWrite(this.regPath + "margin_top", this.marginTop);this.wsShell.RegWrite(this.regPath + "margin_bottom", this.marginBottom);this.wsShell.RegWrite(this.regPath + "margin_left", this.marginLeft);this.wsShell.RegWrite(this.regPath + "margin_right", this.marginRight);this.setOrientation(this.portrain);}JSActiveXPrinter.prototype.recoverPageSetup = function(){this.wsShell.RegWrite(this.regPath + "header", this.localHeader);this.wsShell.RegWrite(this.regPath + "footer", this.localFooter);this.wsShell.RegWrite(this.regPath + "margin_top", this.localMarginTop);this.wsShell.RegWrite(this.regPath + "margin_bottom", this.localMarginBottom);this.wsShell.RegWrite(this.regPath + "margin_left", this.localMarginLeft);this.wsShell.RegWrite(this.regPath + "margin_right", this.localMarginRight);}
2.横向打印
系统和IE自带控件并不支持打印设置API,网上也有几种方法:
(1) 模拟法:成效好,实际就是通过JS控制键盘快捷键进行IE的页面设置
var ws = new ActiveXObject("WScript.Shell");ws.sendKeys("%fu");ws.sendKeys("%a");ws.sendKeys("{ENTER}");上面的代码表示:a. "Alt + f + u"呼出“页面设置” --> b. "Alt + a"选择横向打印 --> "确定“
PS:此法有很大的不可控性,首先代码执行期间不可受干扰,各个快捷键的执行有时需要使用setTimeout进行延迟操作才能起效
(2) CSS滤镜法:
filter: progid:DXImageTransform.Microsoft.BasicImage(Rotation=1);
PS:
a. 注意翻转后的尺寸,超出了会遮掩内容以及出现空白页。
b. 关于分页——使用空白DIV和"page-break-before:aways"之类的样式可以使各个翻转框可有效分页,防止“粘黏”现象。
1、CSS滤镜效果作用于页面加载后,所以被翻转元素的宽度、高度会一起“翻转”。
2、IE打印效果为水平内容会被压缩或者超出部分被忽略,垂直内容超出部分会翻页,用打印预览在不同比例下看一下就知道了。
3、最好使用DIV等元素包裹待翻转内容,并设置初始宽度、高度,不然可能会出现内容字体变大、超出可打印区域部分内容被忽略等情况。
3. 屏蔽打印设置对话窗
使用ActiveX控件WebBrowser可以控制IE部分功能。
当使用window.print()函数进行打印功能调用的时候,可以使用VBScript重写print()函数(虽然Javascript也能重写,但是调用WebBrowser的时候却不能成功屏蔽打印设这对话)。
<Script language="VBScript"> Sub Print() call WB.EXECWB(6,2,1) End Sub</Script>
- IE下使用js与自带ActiveX控制web打印
- WEB打印解决方案之一--IE自带ActiveX控件
- ie自带打印
- ie自带的打印
- 利用IE自带打印
- 使用IE自带的打印控件进行套打
- 使用IE自带的打印控件进行套打
- IE下使用js调用系统activex实现文件下载
- IE 下自带打印控件,直接打印,完成测试,可用。
- ASP-调用IE自带打印功能
- IE浏览器自带打印控件WebBrowser
- IE 打印之activex
- 使用Js脚本 修改控制IE的注册表相关设置(activex等)
- 使用Js脚本 修改控制IE的注册表相关设置(activex等)
- 使用Js脚本 修改控制IE的注册表相关设置(activex等)
- 使用Js脚本 修改控制IE的注册表相关设置(activex等)
- js打印和ie自带打印(从别的地方复制过来的方便自己以后用)
- JS----打印分布,设置打印,自带的打印预览
- smarty3.0中文手册文档API及使用指南
- 杭电2005
- Hibernate、Spring和Struts工作原理及使用理由
- Intent
- Java之美之集合类
- IE下使用js与自带ActiveX控制web打印
- 容易忽略的相近词,检验我们生命的成色
- _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
- HDOJ2046(动态规划)
- Win32 - 关于UNICODE编码
- 介绍一下android uboot下擦除inand 的命令:mmc erase boot 0 0 1000
- 安装Windows Server 2008 R2故障转移群集注意事项
- Codeforces Round #178 (Div. 2)
- [翻译][php扩展开发和嵌入式]第11章-php5对象