<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ASP实现精准打印组件</title>
</head>
<style>
body {font-size:14px}
input{border-color: #ffccff; border-style: solid; border-width: 0px 0px 1px}
</style>
<!-- 插入打印控件 -->
<OBJECT ID="jatoolsPrinter" CLASSID="CLSID:B43D3361-D975-4BE2-87FE-057188254255" codebase="atoolsP.cab#version=1,2,0,5" width="192" height="8"></OBJECT>
<script>
function doPrint(how)
{
if(typeof(jatoolsPrinter.page_div_prefix)=='undefined'){
alert("请按页顶上的黄色提示下载ActiveX控件.如果没有提示请按以下步骤设置ie./n 工具-> internet 选项->安全->自定义级别,设置 ‘下载未签名的 ActiveX ’为'启用'状态")
return ;
}
//打印文档对象
var myreport ={
print_settings:{
// 如果想使用默认打印机,不需要设置
// printer: '联想激打',
// 指定纸张的高宽以毫米为单位,本设置实际是指定为a4大小
pageWidth : 2100,
pageHeight : 2970,
// 指定打打印方向为纵向, 1/2 = 纵向/横向
orientation : 1
},
//待保留的打印设置id,打印后将被保存在注册表中,
//下一次启动相同值的print_settings_id,打印文档时,控件将用保留的参数,自动设置打印机
print_settings_id : "mysettings2",
documents: document,
copyrights:Aloesky 版权所有
};
// 调用打印方法
if(how == '打印预览...')
jatoolsPrinter.printPreview(myreport ); // 打印预览
else if(how == '打印...')
jatoolsPrinter.print(myreport ,true); // 打印前弹出打印设置对话框
else
jatoolsPrinter.print(myreport ,false); // 不弹出对话框打印
}
</script>
<table border="0" cellpadding="0" cellspacing="0" width="660" id="AutoNumber1">
<tr>
<td width="100%" valign="top" align="center"><input type="button" value="打印预览..." onClick="doPrint('打印预览...')">
<input type="button" value="打印" onClick="doPrint('打印')">
</td>
</tr>
</table>
<body>
<%
dbdriver="microsoft.jet.oledb.4.0"
dbpath=server.mappath("rymd.mdb")
set conn=server.CreateObject("adodb.connection")
conn.provider=dbdriver
conn.open dbpath
%>
<%
id=trim(request("id"))
if id="" then id=0
%>
<form method="POST" action="rymd.asp">
<input type="text" name="id" size="14" value=<%=id+1%>><input type="submit" value="下一条" name="B1">
</form>
当前打印编号<%=id%>. 只有下面的内容才会被打印,你可以直接修改下面的内容---工作证打印程序。边距和高度的调整,只需调整表格的边距和高度即可</p>
<div id="page1">
<%
set rs=server.CreateObject("adodb.recordset")
sql="select top 1 * from rymd where id="&id&""
rs.open sql,conn,1,1
%>
<% do while not rs.eof %>
<table border="0" width="660" id="table1" cellpadding="0" style="width: 660; position:relative; left:175" cellspacing="0" height="40" >
<tr>
<td >
<input type="text" name="T1" size="20" value=<%=rs("bh")%> style="font-size: 14pt"></td>
</tr>
</table>
<table border="0" width="100%" id="table2" cellspacing="0" cellpadding="0" style="width: 660; position:relative; left:175" height="40">
<tr>
<td>
<input type="text" name="T1" size="20" value=<%=rs("xm")%> style="font-size: 14pt">
</td>
</tr>
</table>
<table border="0" width="100%" id="table3" cellspacing="0" cellpadding="0" style="width: 660; position:relative; left:175" height="40">
<tr>
<td><input type="text" name="T1" size="20" value=<%=rs("zw")%> style="font-size: 14pt"></td>
</tr>
</table>
<table border="0" width="100%" id="table4" cellspacing="0" cellpadding="0" style="width: 660; position:relative; left:175" height="40">
<tr>
<td><input type="text" name="T1" size="20" value=<%=rs("dw")%> style="font-size: 14pt"></td>
</tr>
</table>
<%
rs.movenext
loop
%>
</div>
</body>
</html>
B/S程序中WEB打印的完美解决方案2007年03月19日 星期一 上午 01:02方案一:ScriptX打印组件
方案二:WsReport打印组件
我们首先来说一下方案一:
听说这个组件已经是2006年的事情了,那时候自己为了开发一个事业单位的办证系统用到了定制格式打印功能,为了解决此问题,因此在破解了wsreport组件,并且在优快云中对外公布了出来,没想到这一公布颇具波澜,很多朋友纷纷向我索要此组件,其中有一位朋友提到了这个scriptx,说其功能如何强大,可惜是美国人开发的,读不懂英文,所以没有办法使用。因此让我来研究一下,但是一直以来我的时间一向比较紧迫,所以直到今天用到此组件的时候才不得已啃了这块硬骨头,当你进入scriptx的官方网站的时候,看了他的使用说明会让你一头雾水,莫不这头脑,并且如果按照他提供的实例程序来运行测试程序,也是根本就不能通过的,看了半天让我晕晕乎乎的摸不着北。
最后不得已,只有放弃官方的使用说明,然后结合自己的经验进行测试,当然结果是可想而知的,最终是成功了。我所采用的方法是仅仅使用官方提供的最新版本的.cab文件,cab文件是一个封包文件,该文件往往包含多个文件在其内,即通常所说的客户端activex,当用户第一次浏览网站的时候,该cab文件会自动下载并安装到客户端的电脑上,务须在服务器端注册,因此使用非常简单。闲话少叙,言归正传,让我们首先去官方下载cab文件,然后看如下代码就明白了。
<!--这里调用控件ScriptX.cab-->
<object id= "factory " style= "DISPLAY: none " viewastext classid= "clsid:1663ed61-23eb-11d2-b92f-008048fdd814 " codebase= "http://www.a.com/smsx.cab#Version=6,3,434,26 "> </object>
<SCRIPT defer>
//用于设置打印参数
function printBase() {
factory.printing.footer = "页眉 " //页眉
factory.printing.footer = "页脚 " //页脚
factory.printing.portrait = false //true为纵向打印,false为横向打印
factory.printing.leftMargin = 1.5 //左页边距
factory.printing.topMargin = 0.5 //上页边距
factory.printing.rightMargin = 0.5 //右页边距
factory.printing.bottomMargin = 1.0 //下页边距
}
//用于调用设置打印参数的方法和显示预览界面
function printReport(){
printBase();
//window.print();
factory.printing.Preview();
}
//使界面最大化
maxWin();
function maxWin()
{
var aw = screen.availWidth;
var ah = screen.availHeight;
window.moveTo(0, 0);
window.resizeTo(aw, ah);
}
</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> 查询打印 </b> </font> </td>
</tr>
<tr>
<td align= "center ">
<div id= "divReport " name= "divReport ">
<input type= "button " name= "cmdPRINT " id= "cmdPRINT " οnclick= "printReport() " value= "打印 ">
<input type= "button " οnclick= "window.close(); " value= "关闭 ">
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
在上边的代码中,大家需要注意以下 <object id= "factory " style= "DISPLAY: none " viewastext classid= "clsid:1663ed61-23eb-11d2-b92f-008048fdd814 " codebase= "http://www.a.com/smsx.cab#Version=6,3,434,26 "> </object>
这段代码用来加载cab文件,clsid和codebase必须要和你下载的cab中的信息对应,否则组件会加载错误,这两项其实不难找,只要你用winrar打开你下载的cab文件,然后找到扩展名是.inf的文件,然后打开之,就能看到了。
使用范围:该组件针对打印大篇幅的文档非常好,对于那些对打印定位要求不是非常严格的东西。但是如果用它来打印增值税专用发票或者打印支票就不可以了。因为增值税专用发票类的东西对定位的要求非常的严格,那么这些东西我们用什么组件来打印呢?方法在下边,让我们看一下方案二就知道了。
我们再来看一下方案二:
wsreport这个组件可以用来打印对定位要求非常严格的内容,例如增值税专用发票,既然定位准确,那么控制的时候肯定就有难度,不过没关系,这个组件附带详细的使用说明,并且保证你能够看懂,呵呵,因为是国人开发的。不过这个组件是需要注册的,,非注册版本不能打印连续的分页,另外打印出来的文档永远都有“试用”二字,如果你想突破这些限制,那就自己破解吧,不要向我索要。
===============
使用一个打印控件,jatoolsPrinter,就可以做到打印web页面中的任何部分,我们先来设计一个web页面,如下所示:
<html>
<head>
<title>我的第一个打印文档</title>
</head>
<body bgcolor="#e0e0e0">
<div id='page1' style='background:#ffffff;margin:10;width:270;height:450;float:left'>文档第一页</div>
<div id='page2' style='background:#ffffff;margin:10;width:270;height:450;float:left'>文档第二页</div>
</body>
</html>
在这个文档中,有两个div对象,现在我想把这两个div对象打印输出,每个div作为单独的一页进行打印。显然ie没有提供这样的功能, 在ie中,您不能指定哪些元素打印在第一页,哪些元素打印在第二页等等,但是,jatoolsPrinter做到了,我们来看看jatoolsPrinter是如何做到的,现在我们就在页面中插入这个控件,如下所示。
<html>
<head>
<title>我的第一个打印文档</title>
<!-- 插入打印控件 -->
<OBJECT ID="jatoolsPrinter" CLASSID="CLSID:B43D3361-D975-4BE2-87FE-057188254255" codebase="jatoolsP.cab#version=1,2,0,7"></OBJECT>
</head>
<body bgcolor="#e0e0e0">
<div id='page1' style='background:#ffffff;margin:10;width:270;height:450;float:left'>文档第一页</div>
<div id='page2' style='background:#ffffff;margin:10;width:270;height:450;float:left'>文档第二页</div>
</body>
</html>
这个控件的id是 jatoolsPrinter,这个控件有一个方法是 print 用来打印一系列div对象。请看下面的脚本:
function doPrint()
{
myreport = {
// 要打印的div 对象在本文档中,控件将从本文档中的 id 为 'page1' 的div对象,作为首页打印
// id 为 'page2' 的作为第二页打印
documents:document;
};
jatoolsPrinter.print(myreport,false); // 直接打印,不弹出打印机设置对话框
}
由上可见,您打印若干 div对象时,需要告诉控件,这些div们所属的文档对象(html的document对象),另外,这些div对象的id,也需要按 ‘page+序号‘ 的规则命名,序号从1开始计,也就是说,id为'page1'的div对象,总是作为首页打印。这些设置使用一个javascript对象来描述,也就是上面的myreport对象,具体使用方法请参 考文档打印对象 ,下面是完整的html代码:
<html>
<head>
<title>我的第一个打印文档</title>
<!-- 插入打印控件 -->
<OBJECT ID="jatoolsPrinter" CLASSID="CLSID:B43D3361-D975-4BE2-87FE-057188254255" codebase="jatoolsP.cab#version=1,2,0,7"></OBJECT>
<script>
function doPrint()
{
myreport = {
documents:document,
copyrights:'杰创软件拥有版权 www.jatools.com' // 版权声明,必须
};
jatoolsPrinter.print(myreport,false); // 直接打印,不弹出打印机设置对话框
}
<script>
</head>
<body bgcolor="#e0e0e0">
<div id='page1' style='background:#ffffff;margin:10;width:270;height:450;float:left'>文档第一页</div>
<div id='page2' style='background:#ffffff;margin:10;width:270;height:450;float:left'>文档第二页</div>
<input type="button" value="按钮" onClick='doPrint()'>
</body>
</html>
jatoolsPrinter官方网站 http://print.jatools.com
新的web打印方法,与大家共享
使用一个打印控件,jatoolsPrinter,就可以做到打印web页面中的任何部分,我们先来设计一个web页面,如下所示:
<html>
<head>
<title>我的第一个打印文档</title>
</head>
<body bgcolor="#e0e0e0">
<div id=page1 style=background:#ffffff;margin:10;width:270;height:450;float:left>文档第一页</div>
<div id=page2 style=background:#ffffff;margin:10;width:270;height:450;float:left>文档第二页</div>
</body>
</html>
在这个文档中,有两个div对象,现在我想把这两个div对象打印输出,每个div作为单独的一页进行打印。显然ie没有提供这样的功能, 在ie中,您不能指定哪些元素打印在第一页,哪些元素打印在第二页等等,但是,jatoolsPrinter做到了,我们来看看jatoolsPrinter是如何做到的,现在我们就在页面中插入这个控件,如下所示。
<html>
<head>
<title>我的第一个打印文档</title>
<!-- 插入打印控件 -->
<OBJECT ID="jatoolsPrinter" CLASSID="CLSID:B43D3361-D975-4BE2-87FE-057188254255" codebase="jatoolsP.cab#version=1,2,0,7"></OBJECT>
</head>
<body bgcolor="#e0e0e0">
<div id=page1 style=background:#ffffff;margin:10;width:270;height:450;float:left>文档第一页</div>
<div id=page2 style=background:#ffffff;margin:10;width:270;height:450;float:left>文档第二页</div>
</body>
</html>
这个控件的id是 jatoolsPrinter,这个控件有一个方法是 print 用来打印一系列div对象。请看下面的脚本:
function doPrint()
{
myreport = {
// 要打印的div 对象在本文档中,控件将从本文档中的 id 为 page1 的div对象,作为首页打印
// id 为 page2 的作为第二页打印
documents:document;
};
jatoolsPrinter.print(myreport,false); // 直接打印,不弹出打印机设置对话框
}
由上可见,您打印若干 div对象时,需要告诉控件,这些div们所属的文档对象(html的document对象),另外,这些div对象的id,也需要按 ‘page+序号‘ 的规则命名,序号从1开始计,也就是说,id为page1的div对象,总是作为首页打印。这些设置使用一个javascript对象来描述,也就是上面的myreport对象,具体使用方法请参 考文档打印对象 ,下面是完整的html代码:
<html>
<head>
<title>我的第一个打印文档</title>
<!-- 插入打印控件 -->
<OBJECT ID="jatoolsPrinter" CLASSID="CLSID:B43D3361-D975-4BE2-87FE-057188254255" codebase="jatoolsP.cab#version=1,2,0,7"></OBJECT>
<script>
function doPrint()
{
myreport = {
documents:document,
copyrights:杰创软件拥有版权 www.jatools.com // 版权声明,必须
};
jatoolsPrinter.print(myreport,false); // 直接打印,不弹出打印机设置对话框
}
<script>
</head>
<body bgcolor="#e0e0e0">
<div id=page1 style=background:#ffffff;margin:10;width:270;height:450;float:left>文档第一页</div>
<div id=page2 style=background:#ffffff;margin:10;width:270;height:450;float:left>文档第二页</div>
<input type="button" value="按钮" onClick=doPrint()>
</body>
</html>