1. window.print(); 打印
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
<
input
class
="NOPRINT"
type
="button"
onclick
="window.print()"
value
="print"
>
即可实现打印
如果要实现页面的局部打印,有两种办法
1).利用style,不需要打印的地方都加上 NoPrint Style
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
<
style
media
=print
>
.Noprint
{
display
:
none
;
}
.PageNext
{
page-break-after
:
always
;
}
</
style
>
<
asp:Panel
ID
="Panel1"
Width
=98%
runat
="server"
CssClass
="NOPRINT"
>
..
</
asp:Panel
>
<
table
border
="0"
cellpadding
="0"
cellspacing
="0"
id
="TABLE1"
>
<
tr
class
="NOPRINT"
>
.
</
tr
>
</
table
>
如果实现动态打印,可以用弹出对话框或radioButton来控制需要动态打印地方的 Class
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
<
TABLE
Width
="98%"
align
="center"
cellspacing
="0"
border
="1"
style
="border-collapse:collapse;"
>
<
tr
>
</
tr
>
<
tr
>
</
tr
>
<
tr
id
="SignTR"
>
<!--
动态打印部分
-->
<
td
nowrap style
="width: 10%"
colspan
="2"
>
</
td
>
<
td
width
="90%"
nowrap
>
</
td
>
</
tr
>
</
TABLE
>
<
asp:Panel
ID
="Panel2"
runat
=server
CssClass
="NOPRINT"
>
是否要将签核过程打印在页面后
<
input
type
="radio"
value
="1"
name
="s1"
onclick
="SignTR.className=''"
>
是
<
input
type
="radio"
value
="0"
name
="s2"
onclick
="SignTR.className='NOPRINT'"
>
否
<
input
class
="NOPRINT"
type
="button"
onclick
="window.print()"
value
="打 印"
>
</
asp:Panel
>
<%
--
或者利用Javascript弹出控制
--
%>
<
script
language
="Javascript"
>
function
preview1()
{
var
bln;
var
bln
=
confirm(
"
需要打印签核流程吗?
"
)
if
(bln
==
true
)
{ SignTR.className
=
''
;
}
else
{ SignTR.className
=
'
NOPRINT
'
;
}
window.print();
}
</
script
>
<
input
type
="button"
ID
="printU"
runat
=server
name
="printU"
value
="打印"
onclick
="preview1()"
Class
="button"
>
2).利用利用HTML的字符截取
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
<!--
startprint
-->
<
TABLE
Width
="98%"
cellspacing
="0"
border
="1"
>
<
tr
></
tr
>
<!--
endSign
-->
<
tr
></
tr
>
</
TABLE
>
<!--
endprint
-->
<
script
language
="Javascript"
>
function
preview()
{
var
prnhtml
=
null
;
bdhtml
=
window.document.body.innerHTML;
sprnstr
=
"
<!--startprint-->
"
;
//
开始标识
eprnstr
=
"
<!--endprint-->
"
;
//
结束标识
prnhtml
=
bdhtml.substr(bdhtml.indexOf(sprnstr)
+
17
);
prnhtml
=
prnhtml.substring(
0
,prnhtml.indexOf(eprnstr));
//
截取标识之间部分打印
FGFG
=
window.document.body.innerHTML
window.document.body.innerHTML
=
prnhtml;
window.print();
window.document.body.innerHTML
=
FGFG
//
如果不加此行,没有打印的部分在页面上会隐藏掉
}
</
script
>
如果动态控制打印,可以在JS里面用对话框控制eprnstr 值是<!--endprint--> 或<!--endSign-->
2.利用WebBrowser 打印
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
<
style
media
=print
>
.Noprint
{
display
:
none
;
}
.PageNext
{
page-break-after
:
always
;
}
</
style
>
<%
--
同样要设置Noprint style
--
%>
<
OBJECT
id
=WebBrowser
classid
=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2
height
=0
width
=0
>
</
OBJECT
>
<
input
type
=button
value
=打印
onclick
="document.all.WebBrowser.ExecWB(6,1)"
class
="NOPRINT"
>
<
input
type
=button
value
=直接打印
onclick
="document.all.WebBrowser.ExecWB(6,6)"
class
="NOPRINT"
>
<
input
type
=button
value
=页面设置
onclick
="document.all.WebBrowser.ExecWB(8,1)"
class
="NOPRINT"
>
<
input
type
=button
value
=打印预览
onclick
="document.all.WebBrowser.ExecWB(7,1)"
class
="NOPRINT"
>
WebBrowser.ExecWB(1,1) 打开
WebBrowser.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
WebBrowser.ExecWB(4,1) 保存网页
WebBrowser.ExecWB(6,1) 打印
WebBrowser.ExecWB(7,1) 打印预览
WebBrowser.ExecWB(8,1) 打印页面设置
WebBrowser.ExecWB(10,1) 查看页面属性
WebBrowser.ExecWB(15,1) 好像是撤销,有待确认
WebBrowser.ExecWB(17,1) 全选
WebBrowser.ExecWB(22,1) 刷新
WebBrowser.ExecWB(45,1) 关闭窗体无提示
其中最后一项WebBrowser.ExecWB(45,1)可以有效解决IE7下,使用WebBrowser.ExecWB(7,1)执行打印预览后返回到原窗口时,window.close()方法失效的问题
3.用ScriptX.cab 控件打印
打印的必须文件有2个: 配置文件:setting.js 显示文件:print.js
setting.js 如下:
document.write("<object id=\"factory\" style=\"display:none\" viewastext classid=\"clsid:1663ed61-23eb-11d2-b92f-008048fdd814\" codebase=\"images/events/ScriptX.cab#Version=5,60,0,360\"></object>");
function Printers() {
agree = confirm('确定打印吗?');
if (agree) {
if (agree)
{
NoPrinter.style.visibility='hidden';
factory.printing.Print();}
else NoPrinter.style.visibility='visible';
}
}
factory.printing.header = ""
factory.printing.footer = ""
factory.printing.leftMargin = 0.75
factory.printing.topMargin = 0.75
factory.printing.rightMargin = 0.75
factory.printing.bottomMargin = 0.75
显示文件print.js 如下:
document.write('<style media="print">@media print { .noprint{display:none} } </style>');
/////////////////////////////////~~控制打印时不显示按钮的样式,在页面不需要打印的地方只需要引用该样式即可
document.write('<div id=NoPrinter name=NoPrinter align=right style="visibility:visible" class="noprint"><br> ');
document.write('<input type=button class=button value=关闭 name="bFQ" id="bFQ" onclick=\"javascript\:window.close()\">');
document.write('<input type="button" value="打印设置" onclick=\"factory.printing.PageSetup()\">');
document.write('<input type="button" value="打印预览" onclick=\"factory.printing.Preview()\">');
document.write('<input type=button name=button3 value="打印" onclick="Printers()"> </div>');
在使用打印功能时,只要把文件2个文件包含在页面中放置打印按钮的地方即可,代码如下:
<script src="../inc/print/Printer.js"></script>
<script src="../inc/print/Printers.js"></script>
4.把页面的内容设计成RDLC报表打印出来