WEB打印代码大全(NEW!!)
<object id="factory" style="display:none" viewastext classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"></object>
控件使用教本:
<script defer>
function SetPrintSettings() {
// -- advanced features ,未曾使用过,有待确认。
factory.printing.SetMarginMeasure(2) // measure margins in inches
factory.SetPageRange(false, 1, 3) // need pages from 1 to 3
factory.printing.printer = "HP DeskJet 870C"
factory.printing.copies = 2
factory.printing.collate = true
factory.printing.paperSize = "A4"
factory.printing.paperSource = "Manual feed"
// -- basic features 使用过
factory.printing.header = "This is MeadCo"
factory.printing.footer = "Advanced Printing by ScriptX"
factory.printing.portrait = false //方向,true
factory.printing.leftMargin = 1.0
factory.printing.topMargin = 1.0
factory.printing.rightMargin = 1.0
factory.printing.bottomMargin = 1.0
factory.printing.Print(false) //直接打印,true ,好像不起作用,总是弹出选择打印机窗口
factory.printing.PageSetup() //打印设置
factory.printing.Preview() //打印预览
}
</script>
二、页面加载控件:
OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
控件使用教本:
<script language="javascript">
function printsetup()
{
// 打印页面设置
wb.execwb(8,1);
}
function printpreview()
{
// 打印页面预览
wb.execwb(7,1);
}
function printit()
{
if (confirm('确定打印吗?'))
{
wb.execwb(6,6)
}
}
</script>
====================================================================
关于这个组件还有其他的用法,列举如下:
WebBrowser.ExecWB(1,1) 打开
Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
Web.ExecWB(4,1) 保存网页
Web.ExecWB(6,1) 打印
Web.ExecWB(7,1) 打印预览
Web.ExecWB(8,1) 打印页面设置
Web.ExecWB(10,1) 查看页面属性
Web.ExecWB(15,1) 好像是撤销,有待确认
Web.ExecWB(17,1) 全选
Web.ExecWB(22,1) 刷新
Web.ExecWB(45,1) 关闭窗体无提示
三、修改注册表设置IE打印
<script language="JavaScript">
var hkey_root,hkey_path,hkey_key
hkey_root = "HKEY_CURRENT_USER"
hkey_path = "\Software\Microsoft\Internet Explorer\PageSetup" //IE打印设置的注册表地址
//设置修改函数
function pagesetup_null()
{
var RegWsh = CreateObject("WScript.Shell")
hkey_key="\header"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"" //页眉
hkey_key="\footer"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"" //页脚
hkey_key="\margin_left"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"1" //键值设定--左边边界
hkey_key="\margin_top"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"1" //键值设定--上边边界
hkey_key="\margin_right"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"1" //键值设定--右边边界
hkey_key="\margin_bottom"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"1" //键值设定--下边边界
}
//恢复默认设置
function pagesetup_default()
{
var RegWsh = CreateObject("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" //网址,日期等信息
}
</script>
四、用FileSystem组件实现WEB应用中的本地特定打印
<script Language=JavaScript>
function print_onclick() //打印函数
{
var label
label=document.printinfo.label.value //获得HTML页面的数据
var objfs=CreateObject("Scripting.FileSystemObject") //创建FileSystem组件对象的实例
var objprinter=objfs.CreateTextFile ("LPT1:",true) //建立与打印机的连接
objprinter.Writeline("__________________________________") //输出打印的内容
objprinter.Writeline("| |")
objprinter.Writeline("| 您打印的数据是:"&label& " |”)
objprinter.Writeline("| |")
objprinter.Writeline("|_________________________________|")
objprinter.close //断开与打印机的连接
var objprinter=nothing
var objfs=nothing // 关闭FileSystem组件对象
}
</script>