JavaScript 实现網頁打印處理
JavaScript 实现網頁打印處理
发布时间:2016-12-30 来源:查字典编辑
摘要:1、控制"纵打"、横打”和“页面的边距。(1)functionSetPrintSettings(){factory.printing.Set...

1、控制"纵打"、横打”和“页面的边距。

(1)<scriptdefer>

functionSetPrintSettings(){

factory.printing.SetMarginMeasure(2)//measuremarginsininches

factory.SetPageRange(false,1,3)//needpagesfrom1to3

factory.printing.printer="HPDeskJet870C"

factory.printing.copies=2

factory.printing.collate=true

factory.printing.paperSize="A4"

factory.printing.paperSource="Manualfeed"

factory.printing.header="ThisisMeadCo"

factory.printing.footer="AdvancedPrintingbyScriptX"

factory.printing.portrait=false

factory.printing.leftMargin=1.0

factory.printing.topMargin=1.0

factory.printing.rightMargin=1.0

factory.printing.bottomMargin=1.0

}

</script>

2)

<scriptlanguage="&#106avascript">

functionprintsetup(){

//打印页面设置

wb.execwb(8,1);

}

functionprintpreview(){

//打印页面预览

wb.execwb(7,1);}

functionprintit()

{

if(confirm('确定打印吗?')){

wb.execwb(6,6)

}

}

</script>

</head>

<body>

<OBJECTclassid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"height=0id=wbname=wbwidth=0></OBJECT>

<inputtype=buttonname=button_print&#118alue="打印"

&#111nclick="&#106avascript:printit()">

<inputtype=buttonname=button_setup&#118alue="打印页面设置"

#111nclick="&#106avascript:printsetup();">

<inputtype=buttonname=button_show&#118alue="打印预览"

&#111nclick="&#106avascript:printpreview();">

<inputtype=buttonname=button_fh&#118alue="关闭"

&#111nclick="&#106avascript:window.close();">

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)关闭窗体无提示

2、分页打印

<HTML>

<HEAD>

<STYLE>

P{page-break-after:always}

</STYLE>

</HEAD>

<BODY>

<%whilenotrs.eof%>

<P><%=rs(0)%></P>

<%rs.movenext%>

<%wend%>

</BODY>

</HTML>

3、ASP页面打印时如何去掉页面底部的路径和顶端的页码编号

(1)ie的文件-〉页面设置-〉讲里面的页眉和页脚里面的东西都去掉,打印就不出来了。

(2)<HTML>

<HEAD>

<TITLE>NewDocument</TITLE>

<METANAME="Generator"CONTENT="EditPlus">

<METANAME="Author"CONTENT="YC">

<scriptlanguage="VBScript">

dimhkey_root,hkey_path,hkey_key

hkey_root="HKEY_CURRENT_USER"

hkey_path="SoftwareMicrosoftInternetExplorerPageSetup"

'//设置网页打印的页眉页脚为空

functionpagesetup_null()

onerrorresumenext

SetRegWsh=CreateObject("WScript.Shell")

hkey_key="header"

RegWsh.RegWritehkey_root+hkey_path+hkey_key,""

hkey_key="footer"

RegWsh.RegWritehkey_root+hkey_path+hkey_key,""

endfunction

'//设置网页打印的页眉页脚为默认值

functionpagesetup_default()

onerrorresumenext

SetRegWsh=CreateObject("WScript.Shell")

hkey_key="header"

RegWsh.RegWritehkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P"

hkey_key="footer"

RegWsh.RegWritehkey_root+hkey_path+hkey_key,"&u&b&d"

endfunction

</script>

</HEAD>

<BODY>

<br/>

<br/>

<br/>

<br/>

<br/>

<br/><palign=center>

<inputtype="button"&#118alue="清空页码"&#111nclick=pagesetup_null()><inputtype="button"&#118alue="恢复页吗"&#111nclick=pagesetup_default()><br/>

</p>

</BODY>

</HTML>

4、浮动帧打印

<SCRIPTLANGUAGE=&#106avascript>

functionbutton1_&#111nclick(){

varodoc=window.iframe1.document;

varr=odoc.body.createTextRange();

varstxt=r.htmlText;

alert(stxt)

varpwin=window.open("","print");

pwin.document.write(stxt);

pwin.print();

}

</SCRIPT>

4、用FileSystem组件实现WEB应用中的本地特定打印

<scriptLanguage=VBScript>

functionprint_&#111nclick//打印函数

dimlabel

label=document.printinfo.label.&#118alue//获得HTML页面的数据

setobjfs=CreateObject("Scripting.FileSystemObject")//创建FileSystem组件对象的实例

setobjprinter=objfs.CreateTextFile("LPT1:",true)//建立与打印机的连接

objprinter.Writeline("__________________________________")//输出打印的内容

objprinter.Writeline("||")

objprinter.Writeline("|您打印的数据是:"&label&"|”)

objprinter.Writeline("||")

objprinter.Writeline("|_________________________________|")

objprinter.close//断开与打印机的连接

setobjprinter=nothing

setobjfs=nothing//关闭FileSystem组件对象

endfunction

</script>

服务器端脚本:

<%………

setconn=server.CreateObject("adodb.connection")

conn.Open"DSN=name;UID=XXXX;PWD=XXXX;"

setrs=server.CreateObject("adodb.recordset")

rs.Open(“select……”),conn,1,1

……….%>//与数据库进行交互

HTML页面编码:

<HTML>

………

<FORMID=printinfoNAME="printinfo">

<INPUTtype="button"&#118alue="打印>>"id=printname=print>//调用打印函数

<INPUTtype=hiddenid=text1name=label&#118alue=<%=………%>>//保存服务器端传来的数据

………

</HTML>

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类