ScriptX HTML打印控件
dullhunter @ 2007-07-03 09:41 | JAVA
ScriptX HTML打印控件 配合ireport報表- <%@ page language="java" contentType="text/html;charset=GBK"%>
- <%@ page import="net.sf.jasperreports.engine.JasperFillManager"%>
- <%@ page import="com.frameworkset.common.poolman.PreparedDBUtil"%>
- <%@ page import="com.frameworkset.common.poolman.util.SQLResult"%>
- <%@ page import="net.sf.jasperreports.engine.JasperPrint"%>
- <%@ page import="net.sf.jasperreports.engine.JRExporter"%>
- <%@ page import="net.sf.jasperreports.engine.export.JRHtmlExporter"%>
- <%@ page import="net.sf.jasperreports.engine.export.JRHtmlExporterParameter"%>
- <%@ page import="net.sf.jasperreports.engine.JRExporterParameter"%>
- <%@ page import="java.util.*"%>
- <%@ page import="java.sql.*"%>
- <%@ page import="java.net.*"%>
- <%@ page import="java.io.*"%>
- <%@ page import="com.chinacreator.shoa.common.OAUtil"%>
- <script defer="defer">
- function window.onload() {
- // -- advanced features
- factory.printing.SetMarginMeasure(2); // measure margins in inches
- //factory.printing.printer = "HP DeskJet 870C";
- factory.printing.paperSize = "A4";
- factory.printing.paperSource = "Manual feed";
- factory.printing.collate = true;
- factory.printing.copies = 1;
- factory.printing.SetPageRange(false, 1, 1); // need pages from 1 to 3
- // -- basic features
- factory.printing.header = "This is MeadCo";
- factory.printing.font = "宋體";
- factory.printing.footer = "Advanced Printing by ScriptX";
- factory.printing.portrait = false;
- factory.printing.leftMargin = 1.0;
- factory.printing.topMargin = 1.0;
- factory.printing.rightMargin = 1.0;
- factory.printing.bottomMargin = 1.0;
- }
- </script>
- <script language="javascript">
- function printTure() //打印函數
- {
- document.all("dayinDiv").style.display="none";//隱藏按鈕
- factory.printing.Print(true); //調用控件打印
- document.all("dayinDiv").style.display="";//顯示
- }
- function printTurePre() //打印預覽
- {
- document.all("dayinDiv").style.display="none";//隱藏按鈕
- factory.printing.Preview(); //調用控件預覽
- document.all("dayinDiv").style.display="";//顯示
- }
- function printTureSet() //設置函數
- {
- document.all("dayinDiv").style.display="none";//隱藏按鈕
- factory.printing.PageSetup(); //調用控件設置
- document.all("dayinDiv").style.display="";//顯示
- }
- </script>
- <div id="dayinDiv" style="display: block;" name="dayinDiv">
- <input value="打印本頁" class="buttonActive" οnclick="printTure()" type="button">
- <input value="頁面設置" class="buttonActive" οnclick="printTureSet()" type="button">
- <input value="打印預覽" class="buttonActive" οnclick="printTurePre()" type="button">
- </div>
- <% String id = request.getParameter("id");
- String type = request.getParameter("type");
- String filename = "";
- String tablename = "arch_dispatch";//發文
- if("1".equals(type)){
- filename = "fawen.jasper";//發文
- } else if("2".equals(type)){
- filename = "audit.jasper";//模塊上線
- tablename = "td_workflow_use_audit";
- } else{//收文
- filename = "shouwen.jasper";
- tablename = "arch_receive";
- }
- URL url = OAUtil.class.getResource("OAUtil.class");
- String pkgName = OAUtil.class.getPackage().getName();
- pkgName = pkgName.replace('.', '/');
- String filePath = url.getFile();
- String webinfoPath = filePath.substring(1, filePath.indexOf("WEB-INF/classes/" + pkgName));
- //out.println(webinfoPath);
- try {
- JasperPrint jp = null;
- java.util.Map map = new java.util.HashMap();
- java.sql.Connection con = null;
- PreparedDBUtil pd = new PreparedDBUtil();
- con = pd.getConection();
- map.put("SQLSTR", "select * from "+tablename+" where id ='"+id+"'");
- if("0".equals(type)){
- String tmpsql = "select id, createman,trans_flag,createdept,receive_no_postfix,receive_no1,pishinameid, pishiname,yuewennameid,yuewenname,yuebannameid,yuebanname,deptdealmanid,deptdealman, arch_co,arch_no,receive_no,secrecy_grade,title,to_char(createdate,'yyyy') ||' 年 '||to_char(createdate,'mm')||' 月 '||to_char(createdate,'dd')||' 日 ' as createdate,to_char(receivedate,'yyyy')||' 年 '||to_char (receivedate,'mm')||' 月 '||to_char(receivedate,'dd')||' 日 ' as receivedate,workmemo,auditmemo,readmemo,deptmemo,fd_num,yuebanren from arch_receive where id = '"+id+"'";
- map.put("SQLSTR", tmpsql);
- } else if("1".equals(type)){//發文
- String subsqlstr = "select t.oldfilename,t.createman from td_afx_file t where t.businessid='"+id+"'";
- map.put("SUBSQLSTR", subsqlstr);
- map.put("SUBREPORT_DIR",webinfoPath);
- }else if("2".equals(type)){
- String tmpsql = "select id, code,createman,to_char(createdate,'yyyy')||' 年 '||to_char(createdate, 'mm')||' 月 '||to_char(createdate,'dd')||' 日 ' as createdate,dept, to_char(usedate,'yyyy')||' 年 '||to_char(usedate,'mm')||' 月 '||to_char (usedate,'dd')||' 日 ' as usedate,title,managerman,deptmemo,managermemo, checkresult,deptresult,managerresult,deptman,deptdate,managerdate,usememo,trans_flag,leader,leaderid from td_workflow_use_audit where id = '"+id+"'";
- map.put("SQLSTR", tmpsql);
- System.out.println(tmpsql);
- }
- jp = JasperFillManager.fillReport(webinfoPath+filename, map, con);
- StringBuffer sout = new StringBuffer();
- try {
- JRExporter exporter = new JRHtmlExporter();
- exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
- exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER,
- sout);
- exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "report_image/");
- exporter.setParameter(JRHtmlExporterParameter.
- IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
- Boolean.TRUE); // 刪除記錄最下面的空行
- exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "");
- exporter.setParameter(JRHtmlExporterParameter.
- BETWEEN_PAGES_HTML, "");
- exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");
- exporter.setParameter(JRHtmlExporterParameter.
- IS_USING_IMAGES_TO_ALIGN,
- Boolean.valueOf(true));
- exporter.exportReport();
- %>
- <!--startprint-->
- <div id="jasper" style="display: block;" name="dayinDiv">
- <%
- out.println(sout.toString());
- %>
- </div>
- <!--endprint-->
- <object id="factory" viewastext="" style="display: none;" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="./ScriptX/smsx.cab#Version=6,2,433,70" height="0" width="0">
- </object>
- <%
- } catch (Exception e) {
- e.printStackTrace();
- sout.append("生成報表數據錯誤!");
- }
- } catch (Exception e1) {
- e1.printStackTrace();
- //System.out.println("final exception");
- }
- %>