在制作的时候需要导入itext-1.3.1.jar、iTextAsian.jar(相关字体的jar)
由于项目吹的急从学到现在就只有1天。到手狂收索了一篇
在用ireport的时候注意要字体引用iTextAsian.jar选择相关的属性
text属性中选择STSong-Light 勾选pdf 后面在选择UniGB-UCS2-H,做完就可以编译。
java在调用就ok这么简单。
导出pdf就这么简单。
String jasper = request.getParameter("jasper");
Map parameters = new HashMap();
Map submap = new HashMap();
Enumeration enu = request.getParameterNames();
String requestname = null;
while (enu.hasMoreElements()) {
requestname = (String) enu.nextElement();
if (requestname.equals("jasper")) {// 排除optid
continue;
} else if (requestname.equals("filename")) {// 排除filename
continue;
} else if (requestname.equals("SHOW_BG")) {// 排除SHOW_BG
continue;
}
parameters.put(requestname, request.getParameter(requestname));
}
parameters.put("BaseDir", application
.getRealPath("/jsp/report/template/"));
submap.put("RYSNBH", "510000000200904280606");
parameters.put("REPORT_PARAMETERS_MAP", submap);
File reportFile = new File(application
.getRealPath("/jsp/report/template/" + jasper + ".jasper"));
net.sf.jasperreports.engine.JasperPrint jasperPrint;
Connection conn = null;
ApplicationContext ctx = WebApplicationContextUtils
.getWebApplicationContext(getServletConfig()
.getServletContext());
IIbatisDBbase ib = (IIbatisDBbase) ctx.getBean("ibatisdbbase");
conn = ib.getConn();
JasperReport jasperReport = (JasperReport) JRLoader
.loadObject(reportFile.getPath());
byte[] bytes = JasperRunManager.runReportToPdf(jasperReport,
parameters, conn);
response.reset();
response.setContentType("application/pdf");
ServletOutputStream ouputStream = response.getOutputStream();
response.setContentLength(bytes.length);
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
conn.close();