如何实现报表的批量打印需求
在 web 报表应用中,经常会遇到批量打印的需求,即点击一次打印按钮,实现多张报表的打印输出。润乾报表提供了两种不同的打印方式(applet 打印、PDF 打印)实现批量打印需求,同时也支持横纵报表打印。下面我们就来看一下每一种方式的具体实现方法。
一、applet 批量打印
1、环境配置要求
applet 打印要求客户端至少正确配置了 jre 环境
目前 applet 打印只支持 IE 内核浏览器
2、实现方法
可通过访问 jsp 拼接参数的方式实现,示例 URL 为:
不带参数:
http://localhost:6868/demo/reportJsp/directprint.jsp?report={t1.rpx}{t2.rpx}
带参数:
http://localhost:6868/demo/reportJsp/directprint.jsp?report={t1.rpx}{t2.rpx(arg1=1;arg2=2)}
参数拼接格式说明:
report={无参数报表名 1}{无参数报表名 2}{报表 1( 参数 1=value1; 参数 2=value2;…)}{报表 2( 参数 1=value1; 参数 2=value2;…)}…&prompt=yes&needSelectPrinter=yes
3、示例源码
directprint.jsp 页面完整代码:
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="com.raqsoft.report.view.*"%>
<html> <body>
<%
//此JSP参数格式为:report={无参数报表名1}{无参数报表名2}{报表1(参数1=value1;参数2=value2;...)}{报表2(参数1=value1;参数2=value2;...)}...&prompt=yes&needSelectPrinter=yes
request.setCharacterEncoding( "UTF-8" );
String report = request.getParameter( "report" );
//"请输入报表文件名及参数串report={无参数报表名}{报表1(参数1=value1;参数2=value2;...)}{报表2(参数1=value1;参数2=value2;...)}..."
if( report == null || report.trim().length() == 0 ) throw new
Exception( ServerMsg.getMessage(request,"jsp.dpArgError") );
String prompt = request.getParameter( "prompt" );
String needSelectPrinter = request.getParameter( "needSelectPrinter" );
String pages = request.getParameter( "pages" );
String copies = request.getParameter( "copies" );
if( pages == null ) pages = "";
if( copies == null ) copies = "1";
String appmap = request.getContextPath();
String serverPort = String.valueOf( request.getServerPort() );
String serverName = request.getServerName();
String appRoot = "http://" + serverName + ":" + serverPort + appmap;
String printLabel = ServerMsg.getMessage(request,"jsp.dpPrint");
%>
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" codebase="<%=appRoot%>/jre-6u24-windows-i586.exe#Version=1,6,0,0" width="80" height="32" id="report1_directPrintApplet" style="vertical-align:middle">
<param name="name" value="report1_directPrintApplet">
<param name="code" value="com.raqsoft.report.view.applet.DirectPrintWithoutShow.class">
<param name="archive" value="<%=appmap%>/raqsoftReportApplet.jar">
<param name="type" value="application/x-java-applet;version=1.6">
<param name="appRoot" value="<%=appRoot%>">
<param name="dataServlet" value="/reportServlet;jsessionid=<%=session.getId()%>?action=1">
<param name="fileName" value="<%=report%>">
<param name="srcType" value="file">
<param name="fontFace" value="dialog">
<param name="fontSize" value="10pt">
<param name="fontColor" value="#808040">
<param name="backColor" value="#126356">
<param name="label" value="<%=printLabel%>">
<param name="needPrintPrompt" value="<%=prompt%>">
<param name="needSelectPrinter" value="<%=needSelectPrinter%>">
<param name="needSetPageSize" value="no">
<param name="scriptable" value="true">
<param name="paramCharset" value="UTF-8">
<param name="blackWhitePrint" value="no">
<param name="mirrorPrint" value="no">
<param name="icon" value="/raqsoft/images/print.gif">
<param name="copies" value="<%=copies%>">
<param name=