java 中如何实现打印

java 中如何实现打印,第1张

js:<object id="WebBrowser" classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height="0" width="0"></object>

<script type="text/javascript">

function userPrintExec()

{

document.WebBrowser.Execwb(7,1)//打印预览

return false

}

function userPrint(){

// var name=document.getElementById("name").value

newwin=window.open("aa.jsp?biaoshi=11111&name=aa")这里改成你的name就行了

if(document.all){

newwin.moveTo(0,0)//新窗口的坐标

newwin.resizeTo(screen.width,screen.height)

//此处可设置窗口大小,如(1024, 768),不设置的话为全屏

}

return false

}

</script> body里加: <body <%if(request.getParameter("biaoshi")!=null) {request.removeAttribute("biaoshi")%>onload="return userPrintExec()"<%}%>>打印按钮: <input type="button" name="Sub" value="打印" OnClick="return userPrint()" style="float:right"/>可以的,接分!

简单点就调用window.print()

你也可以把下面代码放到你JSP中:

<html>

<head>

<title>M</title>

<style type="text/css">

.table{

text-align:center

}

</style>

<style media="print">

.Noprint{display:none}

.PageNext{page-break-after: always}

</style>

</head>

<body>

<center class="Noprint">

<p>

<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)">

<input type="button" value="直接打印" onclick="document.all.WebBrowser.ExecWB(6,6)">

<input type="button" value="页面设置" onclick="document.all.WebBrowser.ExecWB(8,1)">

</p>

<p>

<input type="button" value="打印预览" onclick="document.all.WebBrowser.ExecWB(7,1)"></p>

</center>

aaaa

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11844019.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存