如何使用 ActiveReports 实现直接js实现打印功能能

为什么在WORD中打印时会出现转换为PDF我现在要直接打印,我应该怎么去调?_百度知道FastReport直接打印相关问题整理
FastReport直接打印相关问题整理
最近慧都收集到很多关于直接打印的需求,具体就是点击打印后,需要不出现打印对话框也不预览报表,直接开始打印,这种需求在发票单据、条码标签打印中非常常用。小编整理了几种实现报表直接打印方式,供大家参考。
FastReportVCL
  在中,需要将打印选项的对话框设置为False,也可以用以下代码实现。
1234Report.LoadFromFile('filename');Report.PrepareRReport.PrintOptions.ShowDialog := False;Report.P
FastReport .NET(WinForm)
  使用在WinForm平台上进行报表开发,实现直接打印的方式和VCL相识,将PrintSettings对话框设置为False就行了,也可以使用以下代码实现。
12345Report report = new Report();report.Load(...);report.RegisterData(...);report.PrintSettings.ShowDialog = false;report.Print();
FastReport .NET(WebForm)
  使用FastReport ASP.Net版本开发的Web报表时,是不能直接实现直接打印报表,需要先导出为PDF后,再由Adobe Reader的打印功能间接实现。可以参考以下代码。
123456789101112131415161718192021222324252627282930protected void Button1_Click(object sender, EventArgs e)&{&&&&&FastReport.Utils.Config.WebMode = true;&&&&&&using (Report report = new Report())&&&&&{&&report.Load("your_report.frx");&&report.RegisterData(...);&&report.Prepare();&&&&&FastReport.Export.Pdf.PDFExport pdfExport = new FastReport.Export.Pdf.PDFExport();&&using (MemoryStream strm = new MemoryStream())&&{&&&&&&report.Export(pdfExport, strm);&&&&&&&&&&&&&Response.ClearContent();&&&&&&Response.ClearHeaders();&&&&&&Response.Buffer = true;&&&&&&Response.ContentType = "Application/PDF";&&&&&&Response.AddHeader("Content-Disposition", "filename=report.pdf");&&&&&&&strm.Position = 0;&&&&&&strm.WriteTo(Response.OutputStream);&&&&&&Response.End();&&}&&&&&&}&}
  以上方法是FastReport官方唯一推荐的方法,当然Web报表的直接打印,还有很多替代的方式,如调用IE的HTML页面打印,调用第三方打印插件,如AcitveX打印插件等。但是这些打印方法可能会影响报表的打印质量,浏览器兼容性与稳定性也不能保证,慧都在这里并不提倡。
发表评论:
TA的推荐TA的最新馆藏葡萄城控件产品博客 | 通过 ActiveReports 实现 Web 系统的报表直接打印操作
在一些系统中,并不需要先进行预览操作,而是直接打印报表数据。比如在电子商务系统中客户订单打印功能,操作人员在填写必要的用户数据之后,点击单页按钮便可直接打印客户订单。本文就结合 ActiveReports 来实现 Web 系统中直接打印报表的需求。在 ActiveReports 中实现 Web 客户端直接打印操作,主要是借助 ActiveReports 所提供的 Flash 类型的 WebViewer 控件,该控件可以在加载报表之后直接打印。
首先,创建一个 Web 应用程序,添加 ActiveReports 报表到工程中,并在 aspx 页面中添加 WebViewer 控件,然后设置 WebViewer 的 ViewerType 为 FlashViewer。
然后,在打印按钮单击事件的后台代码中设置 WebViewer1.FlashViewerOptions.PrintOptions.StartPrint =,以实现加载报表之后直接打印。
protected void Button2_Click(object sender, EventArgs e)
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath(@&Reports\rptInvoice.rdlx&)));
// 获取用户输入数据,并传递到报表中。
report.Report.ReportParameters[1].DefaultValue.Values.Add(TextBox1.Text);
report.Report.ReportParameters[2].DefaultValue.Values.Add(TextBox2.Text);
report.Report.ReportParameters[3].DefaultValue.Values.Add(TextBox3.Text);
report.Report.ReportParameters[4].DefaultValue.Values.Add(TextBox4.Text);
report.Report.ReportParameters[5].DefaultValue.Values.Add(TextBox5.Text);
report.Report.ReportParameters[6].DefaultValue.Values.Add(TextBox6.Text);
WebViewer1.Report =
WebViewer1.FlashViewerOptions.PrintOptions.StartPrint = true;
WebViewer1.Visible = true;
WebViewer1.Width = 0;
WebViewer1.Height = 0;
预览打印运行截图:
直接打印运行截图:
源码下载:VS2010 + ActiveReports 7
转载声明:欢迎将本站文章进行转载、演绎或用于商业目的,转载时请注明以下信息文章转自:葡萄城控件产品博客,.cn原文地址:.cn/post//ActiveReports_DirectPrint.aspx
(6) (21) (19) (20) (18) (17) (13) (12)
(15) (27) (25) (25) (24) (8) (20) (22) (16) (15) (4) (13)
(11) (28) (10) (36) (22) (23) (33) (37) (13) (15) (7) (12)
(23) (21) (26) (18) (20) (31) (30) (21) (8) (22) (18) (16)
(16) (225) (2)14703人阅读
javascript(36)
&title&Web打印&/title&
&meta http-equiv=&Content-Type& content=&text/ charset=gb2312&&
&!--media=print 这个属性可以在打印时有效--&
&style media=print&
.Noprint{display:}
.PageNext{page-break-after:}
border-bottom: 1 solid #000000;
border-left: 1 solid #000000;
border-right: 0 solid #
border-top: 0 solid #
border-color: # #000000;
border-style:
border-top-width: 2
border-right-width: 2
border-bottom-width: 1
border-left-width: 1
.NOPRINT {
font-family: &宋体&;
font-size: 9
&center class=&Noprint& &
&OBJECT id=WebBrowser classid=CLSID:A-11D0-A96B-00C04FD705A2 height=0 width=0&
&input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)&
&input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)&
&input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)&
&p& &input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)&
&hr align=&center& width=&90%& size=&1& noshade&
&table width=&90%& border=&0& align=&center& cellpadding=&2& cellspacing=&0& class=&tabp&&
&td colspan=&3& class=&tdp&&第1页&/td&
&td width=&29%& class=&tdp&&&&/td&
&td width=&28%& class=&tdp&&&&/td&
&td width=&43%& class=&tdp&&&&/td&
&td colspan=&3& class=&tdp&&&&/td&
&td colspan=&3& class=&tdp&&&table width=&100%& border=&0& cellspacing=&0& cellpadding=&0&&
&td width=&50%& class=&tdp&&&p&这样的报表&/p&
&p&对一般的要求就够了。&/p&&/td&
&td&&&/td&
&/table&&/td&
&hr align=&center& width=&90%& size=&1& noshade class=&NOPRINT& &
&!--分页--&
&div class=&PageNext&&&/div&
&table width=&90%& border=&0& align=&center& cellpadding=&2& cellspacing=&0& class=&tabp&&
&td class=&tdp&&第2页&/td&
&td class=&tdp&&看到分页了吧&/td&
&td class=&tdp&&&&/td&
&td class=&tdp&&&&/td&
&td class=&tdp&&&table width=&100%& border=&0& cellspacing=&0& cellpadding=&0&&
&td width=&50%& class=&tdp&&&p&这样的报表&/p&
&p&对一般的要求就够了。&/p&&/td&
&td&&&/td&
&/table&&/td&
&hr align=&center& width=&90%& size=&1& noshade class=&NOPRINT& &
&!--分页--&
&div class=&PageNext&&&/div&
&table width=&90%& border=&0& align=&center& cellpadding=&2& cellspacing=&0& class=&tabp&&
&td colspan=&3& class=&tdp&&第1页&/td&
&td width=&29%& class=&tdp&&&&/td&
&td width=&28%& class=&tdp&&&&/td&
&td width=&43%& class=&tdp&&&&/td&
&td colspan=&3& class=&tdp&&&&/td&
&td colspan=&3& class=&tdp&&&table width=&100%& border=&0& cellspacing=&0& cellpadding=&0&&
&td width=&50%& class=&tdp&&&p&这样的报表&/p&
&p&对一般的要求就够了。&/p&&/td&
&td&&&/td&
&/table&&/td&
&hr align=&center& width=&90%& size=&1& noshade class=&NOPRINT& &
&!--分页--&
&div class=&PageNext&&&/div&
&table width=&90%& border=&0& align=&center& cellpadding=&2& cellspacing=&0& class=&tabp&&
&td class=&tdp&&第2页&/td&
&td class=&tdp&&看到分页了吧&/td&
&td class=&tdp&&&&/td&
&td class=&tdp&&&&/td&
&td class=&tdp&&&table width=&100%& border=&0& cellspacing=&0& cellpadding=&0&&
&td width=&50%& class=&tdp&&&p&这样的报表&/p&
&p&对一般的要求就够了。&/p&&/td&
&td&&&/td&
&/table&&/td&
网页打印按钮的源代码:javascript:window.print();&
可以用css控制&
@media print&
.a {display:block}&
.b {display:hidden}&
好像是这样。把你不想打印的部分class设为b&
首先在网页中添加:&
&OBJECT id=&WebBrowser& height=&0& width=&0&classid=&CLSID:A-11D0-A96B-00C04FD705A2& VIEWASTEXT&&
&/OBJECT&&
然后就可以依次加入功能按钮了:&
&input onclick=&document.all.WebBrowser.ExecWB(6,1)& type=&button& value=&打印&&&&
&input onclick=&document.all.WebBrowser.ExecWB(6,6)& type=&button& value=&直接打印&&&
&input onclick=&document.all.WebBrowser.ExecWB(8,1)& type=&button& value=&页面设置&&&
&input onclick=&document.all.WebBrowser.ExecWB(7,1)& type=&button& value=&打印预览&&&
&INPUT type=&button& value=&关闭窗口& onclick=&javascript:window.close()&&&
将这两块东西放到&center class=noprint&&/center&就不会打印这些按钮了。当然要定义noprint了:&
&style media=&print&&&
& .Noprint { DISPLAY: none }&
只要把不想打印的东西的css设置成noprint就可以了。&
现在就实现了基本的web打印版权保护,需要注意的情况如下:&
&& 1. 必须将ie的internet选项的安全设置中对于没有标记为安全的ActiveX控件进行...设置成提示或者启用版权保护,否则会报错版权保护,导致不可用。&
&& 2. 如果在vs.net编辑环境下编辑该页面版权保护,它经常自动的给object添加多余的参数版权保护,有了这些东西版权保护,打印就会出错版权保护,所以要记得最后保存的时候删除它们。&
为了简便并且达到最好的效果版权保护,我们可以在一个页面实现编辑和打印版权保护,这时候会需要很多的textbox版权保护,我们把它的css设置成&
.edittext{&
overflow-y:&
width: 100%;&
border-top:&
border-right:&
border-bottom:&
border-left:&
就可以实现在打印的时候不显示边框和multiline的textbox不显示滚动条了。&
还有一些小经验就是在设置标格宽度的时候版权保护,对于A4纸张版权保护,横打用920版权保护,竖打用640版权保护,效果最好。相信用B/S方式做过应用的人都可能会遇到这样一个问题版权保护,如何方便、美观地实现报表打印。如果使用浏览器的打印菜单打印的话版权保护,将把网页上的一些无用的东西打到报表上版权保护,比如应用菜单等。因为选择打印菜单打印网页将会把网页中的所有内容全部打印出来版权保护,如果你的应用有分帧则打印内容将包括各帧中的内容版权保护,而你实际要的内容只是其中一部分。所以有很多应用就只能把打印功能放到后台完成了。&
针对这种情况版权保护,我们该怎么办?其实可以有多种方法实现网页打印功能。&
第 一种方法就是使用专业的打印工具版权保护,如Crystal Reports(水晶报表)。用过Visual Studio 5.0的朋友肯定记得这个工具版权保护,不过那时的版本只有4.几。现在的最新版本已达9了版权保护,近几个版本的水晶报表都支持WEB打印。最简单的方法是先用水晶报表制作好模板版权保护,然后使用ASP带参数调用制作好的模板即可。水晶报表在网页上生成报表后版权保护,可以直接打印版权保护,也可以转存为其它的比较通用的文件如Excel文件。使用水晶报表可以制作出非常漂亮的样式版权保护,关键在你对水晶报表的开发能力上版权保护,但由于水晶报表价格较高版权保护,只有当项目很赚钱时才买得起。&
第二种方法是购买第三方的网上打印控件版权保护,费用同水晶报表相比便宜版权保护,但效果性能到底如何则仁者见仁了。&
第三种方法是利用样式表及JavaScript自定义函数实现。通过样式表及JavaScript版权保护,实现网页打印版权保护,效果也还可以。在此有一个实例请大家看看。下面是打印函数实现详解:&
<script language=&JavaScript& type=&text/JavaScript&>&
function DP() {&
& if (window.print){&
var Div1 = document.all.Div1.innerHTML;&
var Div2 = document.all.Div2.innerHTML;&
// *****************************************************&
// Div1、Div2即为你在打印的区域&
// 这里根据你要打印的哪些内容版权保护,从原显示页面中用&
// <div id=Div1>Div1....</div><div id=Div2>Div2...</div>&
// 等标示出来,要打印多少项目就标示多少&
// *****************************************************&&
&&& var css = '<style type=&text/css& media=all>' +'p { line-height: 120%}'&&
& +'.ftitle { line-height: 120%; font-size: 18 color: #000000}'&&
&& +'td { font-size: 10 color: #000000}' +'</style>' ;&
& // *****************************************************&
// 定义打印用的CSS版权保护,具体你想打印出什么样的格式全看你自己&
// 了版权保护,但要注意:如果此处有什么同网页中不一致的版权保护,可能打印&
// 出来的页面同网页格式、字体可能会有所不同&
// *****************************************************&
var body ='<table width=&640& border=&0& cellspacing=&0& cellpadding=&5&>'&
+' <tr> '&&
+' <td class=&fbody&> '&&
+' <div align=&center& class=ftitle>' + Div1 + '</div>' + Div2&&
+' </td>' +' </tr>'&&
+'</table>';&
// ******************************************************&
// 在此处重新设置的打印格式版权保护,根据你的打印要求版权保护,将原显示的&
// 网页的DIV内容重新组合版权保护,可以根据你原来的表格内容版权保护,去掉&
// 不要打印的版权保护,你也可以能下面定义的noprint忽略掉你不想打&
// 印的东西版权保护,只调用你要打印的内容版权保护,但这样被忽略掉的地方将&
// 打印出空版权保护,不是很美观。表格宽度要同打印的纸张宽度匹配。&
// ******************************************************&
document.body.innerHTML = '<center>' + css + body + '</center>';&
// ******************************************************&
// 重设document.body版权保护,打印文档准备就绪&
// ******************************************************&
window.print();&
window.history.go(0);&
// ******************************************************&
// 调用打印命令版权保护,打印当前窗口内容。当你打印时其实是一张新&
// 的网页了版权保护,但网页文件还是原先的。紧接着调用&
// window.history.go(0)版权保护,再回到打印前的页面版权保护,效果相当不差&
// ******************************************************&
</script>&
<style>&
& @media print {&
&&& .noprint {display:none}&
</style>&
<!--//.noprint 定义了noprint版权保护,在以下不需要打印的地方加入 class=&noprint&后版权保护,用window.print()打印就会忽略--> 好了版权保护,一切就绪了版权保护,现在要做的就是调用DP函数版权保护,如果你将实现调用的按钮设计在同一张网页上版权保护,则直接调用即可;如果你用了分帧方法版权保护,实现调用的按钮是在另一张网页上版权保护,则在DP函数的第一行加入window.focus()命令版权保护,否则打印的只是有按钮的网页。&
&&& 第四种方法版权保护,实现是一种取巧的方法。一样还是通过调用window.print()实现版权保护,只是将你要打印的内容专门生成一张网页版权保护,而打印按钮在另一帧上。假设报表网页在mainFrame上版权保护,按钮在topFrame上版权保护,按钮调用PrintReports()函数版权保护,PrintReports()函数如下即可实现打印工作。&
function PrintReports(){//topFrame网页中的函数&
&&& // *******************************************************&
&&& // 错误处理版权保护,如果在mainFrame中的网页没有DP函数则不打印&
&&& // *******************************************************&
&&& window.parent.frames(&mainFrame&).DP();&
& }catch(e){&
&&& alert(&no object to print!&);&
function DP() {// mainFrame网页中函数&
& window.focus();&
& if (window.print){&
&&& window.print();&
1、控制&纵打&、 横打”和“页面的边距。&
(1)&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&
factory.printing.leftMargin = 1.0&
factory.printing.topMargin = 1.0&
factory.printing.rightMargin = 1.0&
factory.printing.bottomMargin = 1.0&
&/script&&
&script language=&javascript&&&
function printsetup(){&
// 打印页面设置&
wb.execwb(8,1);&
function printpreview(){&
// 打印页面预览&
wb.execwb(7,1);&
function printit(){&
if (confirm('确定打印吗?')) {&
wb.execwb(6,6)&
&/script&&
&OBJECT classid=&CLSID:A-11D0-A96B-00C04FD705A2&height=0 id=wb name=wb width=0&&/OBJECT&&
&input type=button name=button_print value=&打印&onclick=&javascript:printit()&&&
&input type=button name=button_setup value=&打印页面设置&onclick=&javascript:printsetup();&&&
&input type=button name=button_show value=&打印预览&onclick=&javascript:printpreview();&&&
&input type=button name=button_fh value=&关闭&onclick=&javascript: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、分页打印&
&STYLE&  &
P {page-break-after: always}&
&%while not rs.eof%&&
&P&&%=rs(0)%&&/P&&
&%rs.movenext%&&
3、ASP页面打印时如何去掉页面底部的路径和顶端的页码编号&
(1)ie的文件-〉页面设置-〉讲里面的页眉和页脚里面的东西都去掉版权保护,打印就不出来了。&
(2)&HTML&&
&TITLE& New Document &/TITLE&&
&META NAME=&Generator& CONTENT=&EditPlus&&&
&META NAME=&Author& CONTENT=&YC&&&
&script language=&VBScript&&&
dim hkey_root,hkey_path,hkey_key&
hkey_root=&HKEY_CURRENT_USER&&
hkey_path=&\Software\Microsoft\Internet Explorer\PageSetup&&
'//设置网页打印的页眉页脚为空&
function pagesetup_null()&
on error resume next&
Set 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,&&&
end function&
'//设置网页打印的页眉页脚为默认值&
function pagesetup_default()&
on error resume next&
Set 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&&
end function&
&/script&&
&br/&&p align=center&&
&input type=&button& value=&清空页码& onclick=pagesetup_null()& &input type=&button& value=&恢复页吗& onclick=pagesetup_default()&&br/&&
4、浮动帧打印&
&SCRIPT LANGUAGE=javascript&&
function button1_onclick() {&
var odoc=window.iframe1.&
var r=odoc.body.createTextRange();&
var stxt=r.htmlT&
alert(stxt)&
var pwin=window.open(&&,&print&);&
pwin.document.write(stxt);&
pwin.print();&
&/SCRIPT&&
4、用FileSystem组件实现WEB应用中的本地特定打印&
&script Language=VBScript&&
function print_onclick //打印函数&
dim label&
label=document.printinfo.label.value //获得HTML页面的数据&
set objfs=CreateObject(&Scripting.FileSystemObject&) //创建FileSystem组件对象的实例&
set objprinter=objfs.CreateTextFile (&LPT1:&,true) //建立与打印机的连接&
objprinter.Writeline(&__________________________________&) //输出打印的内容&
objprinter.Writeline(&| |&)&
objprinter.Writeline(&| 您打印的数据是:&&label& & |”)&
objprinter.Writeline(&| |&)&
objprinter.Writeline(&|_________________________________|&)&
objprinter.close //断开与打印机的连接&
set objprinter=nothing&
set objfs=nothing // 关闭FileSystem组件对象&
end function&
&/script&&
服务器端脚本:&
set conn=server.CreateObject (&adodb.connection&)&
conn.Open &DSN=UID=XXXX;PWD=XXXX;&&
set rs=server.CreateObject(&adodb.recordset&)&
rs.Open(“select ……”),conn,1,1&
……….%& //与数据库进行交互&
HTML页面编码:&
&FORM ID=printinfo NAME=&printinfo& &&
&INPUT type=&button& value=&打印&&& id=print name=print & //调用打印函数&
&INPUT type=hidden id=text1 name=label value=&%=………%&& //保存服务器端传来的数据&
————————————————————————————————&
可以控制打印区域打印代码&
先写入以下代码:&
&SCRIPT language=JavaScript&&
function doPrint(){&
var str=&&html&&;&
var strAdBegin=&&!--NEWSZW_HZH_BEGIN--&&;&
var strAdEnd=&&!--NEWSZW_HZH_END--&&;&
var strFontSize='【&A href=&javascript:doZoom(16)&&大&/A& &A href=&javascript:doZoom(14)&&中&/A& &A href=&javascript:doZoom(12)&&小&/A&】'&
var strdoPrint=&doPrint()&;&
css=&&style&&&
+&body{font-family:宋体}&&
+&td,.f12{font-size:12px}&&
+&.f24 {font-size:24}&&
+&.f14 {font-size:14}&&
+&.title14 {font-size:14line-height:130%}&&
+&.l17 {line-height:170%;}&&
+&&/style&&;&
str +=&
str += '&meta http-equiv=&content-type& content=&text/ charset=gb2312&&';&
str += '&title&'+document.title+'&/title&';&
str += &&body bgcolor=#ffffff topmargin=5 leftmargin=5 marginheight=5 marginwidth=5 onLoad='window.print()'&&;&
str += &&center&&table width=600 border=0 cellspacing=0 cellpadding=0&&tr&&td height=34 width=150&&a href=.cn&&img src=.cn/ent/images/sina_xwzx.gif width=144 height=34 border=0 alt=新闻中心&&/a&&/td&&td valign=bottom&&font
color=#0000ff&&a href=.cn/ class=a02&新浪首页&/a& & &a href=.cn/ class=a02&新闻中心&/a& & &正文&/font&&/td&&td align=right valign=bottom&&a href='javascript:history.back()'&返回&/a& &a href='javascript:window.print()'&打印&/a&&/td&&/tr&&/table&&;&
str += &&table width=600 border=0 cellpadding=0 cellspacing=20 bgcolor=#EDF0F5&&tr&&td&&;&
article=document.getElementById('article').innerHTML;&
if(article.indexOf(strAdBegin)!=-1){&
& str +=article.substr(0,article.indexOf(strAdBegin));&
& strTmp=article.substr(article.indexOf(strAdEnd)+strAdEnd.length, article.length);&
& strTmp=article&
str +=strTmp&
str += window.location.href&
str += &&/td&&/tr&&/table&&/center&&;&
str += &&/body&&/html&&;&
document.write(str);&
document.close();&
&/SCRIPT&&
利用&div id=&article&&文章正文&/div& 实际是通过设置id为article的区域来控制打印区域的大小.&
打印按钮:【&A href=&javascript:doPrint()&&打印&/A&】&
————————————————————————————————————&
WebBrowser是IE内置的浏览器控件版权保护,无需用户下载。本文档所讨论的是有关IE6.0版本的WebBrowser控件技术内容。其他版本的IE应该也支持。与其相关的技术要求有:打印文档的生成、页面设置、打印操作的实现等几个环节。本文以asp为例版权保护,但是他可以容易的移植到其他web技术中。&
一、WebBrowser控件&
&object ID='WebBrowser' WIDTH=0 HEIGHT=0 CLASSID='CLSID:A-11D0-A96B-00C04FD705A2'&&/object&&
二、WebBrowder控件的方法&
WebBrowser1.ExecWB(6,1);&
//打印设置&
WebBrowser1.ExecWB(8,1);&
//打印预览&
WebBrowser1.ExecWB(7,1);&
三、实现打印的设置版权保护,打印数据的生成版权保护,打印的预览版权保护,和打印。&
实现打印的设置版权保护,打印数据的生成版权保护,打印的预览版权保护,和打印我一般这样做版权保护,假如查询结果在a.asp中版权保护,那么在a.asp中放置打印设置、打印预览、打印三个按钮。&
单击打印设置按钮则在js中执行WebBrowser1.ExecWB(8,1)版权保护,以打开打印设置窗口。&
单击打印预览按钮则打开一个b.asp,在b.asp中重新生成打印数据版权保护,然后在b.asp中自动执行WebBrowser1.ExecWB(7,1)版权保护,以打开用户预览界面。&
单击打印按钮则也打开b.asp版权保护,在b.asp中重新生成打印数据版权保护,然后在b.asp中自动执行WebBrowser1.ExecWB(6,1)版权保护,以自动打印数据。&
a.asp调用数据的程序就不给出了。只给出几个按钮的代码:&
&input type=“button“ name=“mPrint“ value=“打印“ onclick=“exePrint();“&&
&input type=“button“ name=“mPreview“ value=“打印预览“ onclick=“exePreview();“&&
&input type=“button“ name=“mSetting“ value=“打印设置“ onclick=“exeSetting();“&&
&object ID='WebBrowser' WIDTH=0 HEIGHT=0 CLASSID='CLSID:A-11D0-A96B-00C04FD705A2'&&/object&&
&script language='javascript'&&
function exePrint()&
liu= window.open('b.asp?do=1','_blank','left=2000,top=2000,fullscreen=3');&
function exePreview()&
& window.open('b.asp?do=2','_blank','left=2000,top=2000,fullscreen=3');&
function exeSetting()&
& WebBrowser.ExecWB(8,1);&
&/script&&
代码中打印设置的代码很简单版权保护,大家很容易理解。打印预览和打印的按钮需要告诉b.asp我们将要执行的是打印还是打印预览。另外版权保护,还要将查询字符串传递过去。当然web高手可以尝试其他方法版权保护,以避免反复重服务器调数据版权保护,当然初学者只能通过多次查询版权保护,以牺牲性能来解决打印了。&
假设本例中a.asp通过传递一个查询串打开了b.asp版权保护,则在b.asp中将重新载入数据。在这里载入数据后将数据显示在网页上需要知道每个页要显示多少条(PageSize)。显示的时候&
————————————————————————————&
弹出打印窗口版权保护,去掉网址显示.&
&OBJECT id=factory style=&DISPLAY: none&&
codeBase=/scriptx/ScriptX.cab#Version=5,60,0,360&
classid=clsid:eb-11d2-b92f-008048fdd814 viewastext&&/OBJECT&&
&SCRIPT defer&&
function window.onload() {&
factory.printing.header = &-&&
factory.printing.footer = &-&&
factory.printing.Print(true)&
factory.printing.leftMargin = 0.2&
factory.printing.topMargin = 0.5&
factory.printing.rightMargin = 0.2&
factory.printing.bottomMargin = 1.5&
&/SCRIPT&&
————————————————————————————————&
WEB打印,去页眉和页脚&
作者: 未知&
1. IE浏览器. 文件-&页面设置.&
把页脚去掉就行了.&
2.用代码.&
//有提示的..&
&TITLE& New Document &/TITLE&&
&META NAME=&Generator& CONTENT=&EditPlus&&&
&META NAME=&Author& CONTENT=&YC&&&
&script language=&VBScript&&&
dim hkey_root,hkey_path,hkey_key&
hkey_root=&HKEY_CURRENT_USER&&
hkey_path=&\Software\Microsoft\Internet Explorer\PageSetup&&
'//设置网页打印的页眉页脚为空&
function pagesetup_null()&
on error resume next&
Set 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,&&&
end function&
'//设置网页打印的页眉页脚为默认值&
function pagesetup_default()&
on error resume next&
Set 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&&
end function&
&/script&&
&br&&p align=center&&
&input type=&button& value=&清空页眉& onclick=pagesetup_null()& &input type&
=&button& value=&恢复页眉& onclick=pagesetup_default()&&br&&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:502201次
积分:5982
积分:5982
排名:第2852名
原创:103篇
转载:59篇
评论:131条
(1)(1)(2)(3)(1)(1)(2)(2)(1)(4)(13)(1)(1)(9)(2)(4)(1)(3)(4)(5)(2)(1)(6)(10)(15)(2)(5)(8)(1)(12)(4)(4)(1)(5)(5)(4)(2)(5)(3)(6)(1)

我要回帖

更多关于 java web实现打印功能 的文章

 

随机推荐