批量打印

实例请参考网页脚本控制实例 / 批量直接打印

 

背景说明:

客户端经常需要对报表进行批量打印,此时可以调用applet打印、PDF打印或本地打印进行批量打印操作,用法如下:

applet打印:

<%

//report的参数格式为:report={无参数报表名}{报表1(参数1=value1;参数2=value2;...)}{报表2(参数1=value1;参数2=value2;...)}...prompt=yes

request.setCharacterEncoding( "GBK" );

String report = request.getParameter( "report" );

if( report == null || report.trim().length() == 0 ) throw new Exception( "请输入报表文件名及参数串report={无参数报表名}{报表1(参数1=value1;参数2=value2;...)}{报表2(参数1=value1;参数2=value2;...)}..." );

String prompt = request.getParameter( "prompt" );

String appmap = request.getContextPath();

String serverPort = String.valueOf( request.getServerPort() );

String serverName = request.getServerName();

String appRoot = "http://" + serverName + ":" + serverPort + appmap;

%>

 

<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"  codebase="<%=appRoot%>/jre-6u24-windows-i586.exe #Version=6.0.240.7"  width="40" height="16" id="report1_directPrintApplet" style="vertical-align:middle"> 

<param name="name" value="report1_directPrintApplet">

<param name="code" value="com.raqsoft.report.view.applet.DirectPrintApplet.class">

<param name="archive" value="<%=appmap%>/raqsoftReportApplet.jar"> 

<param name="type" value="application/x-java-applet;version=1.4"> 

<param name="appRoot" value="<%=appRoot%>"> 

<param name="dataServlet" value="/reportServlet?action=1"> 

   

<param name="srcType" value="file"> 

<param name="fontFace" value="宋体"> 

<param name="fontSize" value="18pt"> 

<param name="fontColor" value="#0000FF"> 

<param name="backColor" value="#12632256">

<param name="icon" value= "<%=appmap%>/images/print.gif">//为打印控件的打印按钮设置图片,如果不设置此参数,则打印按钮上不显示图片。

<param name="label" value="打印">   

<param name="needPrintPrompt" value="<%=prompt%>">

<param name="scriptable" value="true">

</object>

  <a href="javascript:window.close()" class="style3 style5">取消</a>

<script language=javascript>

//此函数返回的格式为:"{无参数报表名}{报表1(参数1=value1;参数2=value2;...)}{报表2(参数1=value1;参数2=value2;...)}..."

function raqsoft_getPrintReports() {

//请在此函数里加上打印前需要的处理,最后返回需要打印的报表

return "<%=report%>";

}

</script>

 

PDF打印:

<script language=javascript>

var myToast;

function showToast() {

myToast = $().toastmessage('showToast', {

text : '<%=ServerMsg.getMessage(request,"jsp.loadingPrint")%>',

sticky: true,

position : 'middle-center',

type: 'notice'

});

}

function closeToast() {

$().toastmessage('removeToast', myToast);

}

</script>

……

<%

//report的参数格式为:report={无参数报表名}{报表1(参数1=value1;参数2=value2;...)}{报表2(参数1=value1;参数2=value2;...)}

request.setCharacterEncoding( "UTF-8" );

String report = request.getParameter( "report" );

if( report == null || report.trim().length() == 0 ) throw new Exception( "请输入报表文件名及参数串report={无参数报表名}{报表1(参数1=value1;参数2=value2;...)}{报表2(参数1=value1;参数2=value2;...)}..." );

String src = request.getContextPath() + ServletMappings.getMapping( "com.raqsoft.report.view.ReportServlet" ) + "?action=45&report=" + URLEncoder.encode( report, "UTF-8" );

String preview = request.getParameter( "preview" );

if( "no".equalsIgnoreCase( preview ) ) {

String url = appmap + ReportConfig.raqsoftDir + "/pdfjs/pdfDirectPrint.jsp?src=" + URLEncoder.encode( src, "UTF-8" );

%>

<iframe src="<%=url%>" style="position:absolute;left:-100px;top:-100px" width=50 height=50>

</iframe>

<script language=javascript>

showToast();

</script>

<%

}

else {%>

<object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" id=pdfobj width="100%" height="100%" border="0">

<param name="_Version" value="65539">

<param name="_ExtentX" value="20108">

<param name="_ExtentY" value="10866">

<param name="_StockProps" value="0">

<param name="SRC" value="<%=src%>">

<comment>

<embed id=pdfobj1

type="application/pdf"

src="<%=src%>"

width="100%"

height="95%">

</embed>

</comment>

</object>

<% } %>

 

本地打印:

<%

//report的参数格式为:report={无参数报表名}{报表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" );

String appmap = request.getContextPath();

String appRoot = ReportServlet.getUrlPrefix( request );

if( !appRoot.startsWith( "http" ) ){

String approot1 = request.getRequestURL().toString();

approot1 = approot1.substring( 0, approot1.indexOf( request.getRequestURI() ) );

appRoot = approot1 + appmap;

}

StringBuffer url = new StringBuffer( "printrpx://" );

url.append( "a=" + URLEncoder.encode( appRoot, "UTF-8" ) );

url.append( "&b=" + URLEncoder.encode( "/reportServlet;jsessionid=" + session.getId() + "?action=1", "UTF-8" ) );

url.append( "&c=" + URLEncoder.encode( report, "UTF-8" ) );

if( needSelectPrinter != null ) {

url.append( "&k=" + needSelectPrinter );

}

url.append( "&u=1" );

url.append( "&v=" + prompt );

url.append( "&x=UTF-8" );  //paramCharset

if( pages != null ) url.append( "&z=" + pages );

if( copies != null ) url.append( "&aa=" + copies );

url.append( "&ti=" + System.currentTimeMillis() );

%>