jsp打印

<!--最简单的打印-->
<input type="button" value="打印" οnclick="window.print(window.document.body.innerHTML); "/>&nbsp;
<!--主要内容-->
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0 VIEWASTEXT>
</OBJECT>
<input type=button value=打印     οnclick="document.all.WebBrowser.ExecWB(6,1)" class="NOPRINT">
<input type=button value=直接打印 οnclick="document.all.WebBrowser.ExecWB(6,6)" class="NOPRINT">
<input type=button value=页面设置 οnclick="document.all.WebBrowser.ExecWB(8,1)" class="NOPRINT">
<input type=button value=打印预览 οnclick="document.all.WebBrowser.ExecWB(7,1)" class="NOPRINT">
<!--1.直接调用windows函数   -->
<input   type="button"   value="print"     
οnclick="window.focus();window.print()">   
<!--2.调用js     -->
//放在head   与   head   之间   
<SCRIPT   LANGUAGE=javascript>   
<!--   
function   setPrint()   
{   
WB.ExecWB(8,1);   
}   
function   previewPrint()   
{   
WB.ExecWB(7,1)   
}   
//-->   
</SCRIPT>   
      
//放在body与body之间   
<OBJECT   classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2   height=0   id=WB   width=0>   
</OBJECT>   
<INPUT   type="button"   value="打印设置"   id=button1   name=button1   οnclick="setPrint();">   
<INPUT   type="button"   value="打印预览"   id=button2   name=button2   οnclick="previewPrint();">   

//JSP调用IE控件实现打印 

//2006-09-10 20:57:20 

//大中小 
//调用页面:
function printinfo(){
var seq=document.getElementById("sequence").value;
window.open('SYbracketApplyPtint.jsp?seqstr='+seq,'', 'height=120, width=350, top='+(screen.availHeight-
120)/2+', left='+(screen.availWidth-350)/2+', toolbar=no, menubar=no, scrollbars=no, resizable=no,
location=no, status=yes');
}
//处理页面接收:
String str=new String(request.getParameter("seqstr").getBytes("8859_1"));//避免汉字乱码
//例子代码:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
<jsp:useBean id="connBean" scope="page" class="fkjd.conn_sy" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="main.css" rel="stylesheet" type="text/css">
<title>print</title>
</head>
<script language="javascript">
var hkey_root,hkey_path,hkey_key;
hkey_root="HKEY_CURRENT_USER";
hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
   
//设置网页打印的页眉页脚为空
function pagesetup_null(){
try{
    var RegWsh = new ActiveXObject("WScript.Shell");
    hkey_key="header";
    RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");
    hkey_key="footer";
    RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");
}
catch(e){}
}


</script>
<style type="text/css">
.butt
{
width:50pt; height:15pt;
    background-color:#CCCCCC;
}
.singlelinetext170
{
border-right:#FFFFFF;
border-top:#FFFFFF;
width:170pt;
border-left:#FFFFFF;
border-bottom-color:#E1E1E1;
}
.singlelinetext100
{
border-right:#FFFFFF;
border-top:#FFFFFF;
width:100;
border-left:#FFFFFF;
border-bottom-color:#E1E1E1;
background-color:transparent;
}
.singlelinetext90
{
border-right:#FFFFFF;
border-top:#FFFFFF;
width:90;
border-left:#FFFFFF;
border-bottom-color:#E1E1E1;
background-color:transparent;
}
.singlelinetext45
{
border-right:#FFFFFF;
border-top:#FFFFFF;
width:45pt;
border-left:#FFFFFF;
border-bottom-color:#E1E1E1
}
@media print {
.notprint {
display:none;
}
}
@media screen {
.notprint {
display:inline;
cursor:hand;
}
}
.textbord{
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 1px;
border-left-width: 0px;
border-bottom-style: solid;
border-bottom-color: #000000;
width:70pt;
}
.buttonlh{
width:40pt;
height:15pt;
background-color:#CCCCCC;
}
.st1{
border-collapse:collapse
.bordleft{ border-left-style:none; border-left-width:0px }
.bordright{ border-right-style:none;}
}
</style>
<body onLoad="pagesetup_null()" leftmargin="0" topmargin="0">
<table align="center" class="notprint" width="384" height="125" background="img/printer.jpg">
<tr>
    <td align="center" valign="middle"> 确定要进行打印吗?</td>
</tr>
<tr>
    <td align="center" valign="middle"> <input type=button value="确定" class="buttonlh" onClick="document.all.WebBrowser.ExecWB(6,1),window.close()"> 
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0pt width=0pt></OBJECT>
     <input type="button" value="退出" class="buttonlh" onClick="window.close()"></td>
</tr>
</table>
   <input   type="button"   value="print"     
οnclick="window.focus();window.print()">   

 

具体如下:
<script type="" language="javascript">

function tablePrint()
{
fp=window.open('','','');
//alert(document.getElementById("rr".parentElement.innerHTML);
//print();
fp.document.write(rr.parentElement.innerHTML);
fp.document.write("<script language='javascript'> document.body.insertAdjacentHTML('beforeEnd',    '<object id=\"WebBrowser\" width=0 height=0 \classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\">');WebBrowser.ExecWB(7,1);  </" +"script>";
//fp.document.write("<script language='javascript'></"+"script>";
fp.location.reload();
//fp.close();
}
</script>
………………
<span id="print"> <table border="0" cellspacing="1"   datapagesize="3"cellpadding="1"bgcolor="#D7D7D7" align="center" width="2926"  id="rr">
<tr><td>
………………
…………
</td></tr>
</table></span>
打印预览 <input name="button" type="button"  class="button" onClick="tablePrint();" value="print" >

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值