惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - surprise

首次使用Ajax 大家看一下这是.net的漏洞还是程序有问题,我一时也没搞清,只知道这问题挺怪的 - surprise - 博客园 一道Sql语句问题? 运用C#处理lob数据类型 (Oracle) Sql Server 中image类型迁移到Oracle 中Blob类型出现图片显示不出来,why????请博客们帮忙 在C#中存储Blob类型的数据, windows 2000下最多可以承受有多大容量外存???? 如何使用一个不错的图表组件WebChart(免费) 太爽了博客园有论坛了? 谁能帮我 WebChart组件的使用??? 能不能在博客园内建立一块开源区呀??? 如何在类库项目中添加配置文件?????? 中文版的hibernate pdf教程下载 用Nhibernate怎么实现数据的添加、删除、修改简单程序 介绍Nhibernate网站 俺现在碰到一些问题请大家帮忙??? 俺现在有个程序需要UTC转换为当地时间,哪位大虾会呀??? 我想问一下NHibernate的问题??? 10.1我发现一个非常好的架构NHibernate,我想和大家一起研究
介绍一种Web上打印技术
surprise · 2005-06-17 · via 博客园 - surprise

一、    介绍ScriptX控件

对于B/S架构的项目中,Web打印最是让程序员头痛的技术,在这次项目中运用了第三方控件ScriptX解决了此技术包括各种汇总表,详细清单等等,但最大弊端就是打印的格式是死的,你要打印出怎样的格式必须自己来做,还有就是打印分页,它是按你设置的纸张大小来分的,所以必须人为控制,ScriptX控件所需文件ScriptX.cab。(ScriptX下载地址http://www.meadroid.com/scriptx/freedep.asp

打印功能使用:

⑴ 用户在客户端单击“打印”按钮,第一次使用打印会弹出如下对话框

⑵ 单击“是”按钮,此时会把控件ScriptX下载到本机

⑶ 在打印窗口中有大标题、打印条件、打印列表,单击“打印”按钮进入打印浏览界面。

⑷ 单击“Print”按钮,听打印机声音响起。

二、    一个简单的ScriptX控件使用实例

1.界面文件  WebExample.aspx  (其中kg.css是界面样式在这里就不介绍了)

<%@ Page language="c#" Codebehind="WebExample.aspx.cs" AutoEventWireup="false" Inherits="WebPrint.WebExample" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

       <HEAD>

              <title>一个简单的ScriptX打印</title>

              <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">

              <meta name="CODE_LANGUAGE" Content="C#">

              <meta name="vs_defaultClientScript" content="JavaScript">

              <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

              <LINK href="kg.css" type="text/css" rel="stylesheet">

       </HEAD>

       <body MS_POSITIONING="GridLayout">

              <form id="WebExample" method="post" runat="server">

                     <TABLE width="100%" height="100%">

                            <tr>

                                   <td height="100">

                                   </td>

                            </tr>

                            <tr>

                                   <td style="HEIGHT: 14px" align="center">

                                          <div id="divTableResult" name="divTableResult">

                                                 <asp:Label id="Label1" runat="server" Width="232px" Height="32px" Font-Size="Large">欢迎使用ScriptX打印</asp:Label>

                                          </div>

                                   </td>

                            </tr>

                            <tr>

                                   <td align="center" valign="top">

                                          <div id="divChartResult" name="divChartResult">

                                                 <asp:Image id="Image1" runat="server" ImageUrl="win2000.gif"></asp:Image>

                                          </div>

                                   </td>

                            </tr>

                            <tr>

                                   <td align="center" valign="top">

                                          <input id="btnPrint" style="WIDTH: 32px; HEIGHT: 19px" onclick="printResult();" type="button"

                                                 size="1" value="打印" name="btnPrint">

                                   </td>

                            </tr>

                     </TABLE>

              </form>

              <script language="javascript">

              function printResult()

              {

                     //针对不同模块,设置打印参数

                     var title = 'ScriptX打印';//报表名称

                     var orien = 'true';//打印页面方向,true:纵向打印/false横向打印

                     //参数设置结束

                     var strURL;

                     title = escape(title);

                     //condition = escape(condition);

                     strURL = 'printContainer2.aspx?title='+title+'&orien='+orien;

                     window.open(strURL,'printResult','height=600, width=800, top=0, left=50,toolbar=no , menubar=no, scrollbars=yes, resizable=no, location=no, status=no');

              }

              </script>

       </body>

</HTML>

说明:

⑴ <div id="divTableResult" name="divTableResult">和<div id="divChartResult" name="divChartResult"> 是在printContainer2.aspx文件中定义的传值标签,因此必须要有。

⑵ printResult()方法用来声明传值内容,具体在方法中已说明

2.打印界面   printContainer2.aspx (其中print.css是打印样式就不介绍了)

<%@ Page language="c#" Codebehind="printContainer2.aspx.cs" AutoEventWireup="false" Inherits="WebPrint.printContainer2" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<%

string title = "查询打印";

‘用于title获取标题

if(Request.QueryString["title"].ToString().Trim()!=""){

       title = Request.QueryString["title"].ToString().Trim();

}

‘用于orientation获取打印页面方向,true:纵向打印/false横向打印

string orientation = "true";

if(Request.QueryString["orien"].ToString().Trim()!=""){

       orientation =  Request.QueryString["orien"].ToString().Trim();

}

%>

<html>

       <head>

              <title>ScriptX 打印</title>

              <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">

              <meta name="CODE_LANGUAGE" Content="C#">

              <meta name="vs_defaultClientScript" content="JavaScript">

              <meta http-equiv="content-type" content="text/html; charset=gb2312">

              <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

              <link href="kg.css" rel="stylesheet" type="text/css">

              <link href="print.css" rel="stylesheet" type="text/css"  media="print" >

<script  FOR=document event="onclick">

if(event.srcElement.tagName=='A'){

              //alert('a click!');

              event.cancelBubble = true;

}

</script>

<style type="text/css">

a:link {text-decoration:none}

a:visited {text-decoration:none}

a:active {text-decoration:none}

a:hover {text-decoration:none}

A { COLOR: #000000;TEXT-DECORATION: none; FONT-SIZE: 8pt;FONT-FAMILY: "";}

</style>

       </head>

       <body MS_POSITIONING="GridLayout" >

<!--这里调用控件ScriptX.cab-->

<object id="factory" viewastext  style="display:none"

  classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"

  codebase="ScriptX.cab#Version=6,1,431,2">

</object>

<SCRIPT defer>

//用于设置打印参数

function printBase() {

factory.printing.footer = "&b ScriptX 打印 &b"       //页眉

factory.printing.footer = ""                                 //页脚

factory.printing.portrait = <%=orientation%>             //true为纵向打印,flase为横向打印

factory.printing.leftMargin = 1.5                               //左页边距

factory.printing.topMargin = 0.5                               //上页边距

factory.printing.rightMargin = 0.5                             //右页边距

factory.printing.bottomMargin = 1.0                          //下页边距

}

</SCRIPT>

<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" bordercolor="#FFFFFF">

  <tr bordercolor="#FFFFFF">

    <td >

       <table width="70%" border="0" cellspacing="0" cellpadding="2" align="center">

         <tr>

           <td align="center"><font size="5" face="宋体"><b><div  name="divTitle" id="divTitle"></div></b></font></td>

         </tr>

         <tr>

           <td align="center">

             <div id="divReport" name="divReport">

             <input type="button" name="cmdPRINT" id="cmdPRINT" onclick="printReport()" value="打印">

             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

             <input type="button" onclick="window.close();"  value="关闭">

             </div>

           </td>

         </tr>

       </table>

   </td>

  </tr>

</table>

<table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">

         <tr><td align="center">

<!--  用于显示divTableContainer标签的值 -->

<div id="divTableContainer"  name="divTableContainer"></div>

              </td></tr>

               <tr><td align="center">

<!--  用于显示divChartContainer标签的值 -->

<div id="divChartContainer"  name="divChartContainer"></div>

              </td></tr>

</table>

</body>

<script language="javascript">

//使界面最大化

maxWin();

var needcon='';

document.all.divTitle.innerText = unescape('<%=title%>');

//用于把父窗体的divTableResult和divChartResult标签的值分别转入divTableContainer 和divChartContainer标签中

var tableContent = window.opener.document.all.divTableResult.innerHTML;

tableContent = replaceAll(tableContent,"<A ","<span ");

tableContent = replaceAll(tableContent,"</A> ","</span> ");

tableContent = replaceAll(tableContent,"<a ","<span ");

tableContent = replaceAll(tableContent,"</a> ","</span> ");

tableContent = replaceAll(tableContent,"<input ","<font ");

tableContent = replaceAll(tableContent,"<INPUT ","<font ");

document.all.divTableContainer.innerHTML = tableContent;

document.all.divChartContainer.innerHTML = window.opener.document.all.divChartResult.innerHTML;

//用于调用设置打印参数的方法和显示预览界面

function printReport(){

       printBase();

       //window.print();

       factory.printing.Preview();

}

function replaceAll( str, from, to ) {

    var idx = str.indexOf( from );

    while ( idx > -1 ) {

        str = str.replace( from, to );

        idx = str.indexOf( from );

    }

    return str;

}

function maxWin()

{

     var aw = screen.availWidth;

     var ah = screen.availHeight;

     window.moveTo(0, 0);

     window.resizeTo(aw, ah);

}

</script>

</html>

三、    参考文件
源代码