当前位置:   article > 正文

iReport学习一:中文字体显示_ireport中文

ireport中文

基本的东西请看下面链接:

http://www.open-open.com/doc/list/115

看完上面的文档对于基本iReport都了解的差不多了吧!接下来看看中文字体设置


1、先下载需要的字体文件按如下步骤操作:工具——》选项——》font字体





2、将字体导出成jar包



3、将jar打开把里面的 文件考到项目中即可如图:



程序代码:

  1. package org.share.web;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. import javax.servlet.http.HttpServletRequest;
  12. import net.sf.jasperreports.engine.JRDataSource;
  13. import net.sf.jasperreports.engine.JREmptyDataSource;
  14. import net.sf.jasperreports.engine.JasperExportManager;
  15. import net.sf.jasperreports.engine.JasperFillManager;
  16. import net.sf.jasperreports.engine.JasperPrint;
  17. import net.sf.jasperreports.engine.JasperReport;
  18. import net.sf.jasperreports.engine.JasperRunManager;
  19. import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
  20. import net.sf.jasperreports.engine.util.JRLoader;
  21. import org.share.domain.tree.entity.UserInfo;
  22. import org.springframework.stereotype.Controller;
  23. import org.springframework.web.bind.annotation.RequestMapping;
  24. import org.springframework.web.bind.annotation.RequestMethod;
  25. @Controller
  26. @RequestMapping(value="/CreatePDf")
  27. public class CreatePDf {
  28. @RequestMapping(value="/c",method=RequestMethod.GET)
  29. public void createFilePdf(HttpServletRequest request){
  30. //路径动态录入需要生产的pdf文件位置
  31. String fileepath=request.getSession().getServletContext().getRealPath("template/repConReport.pdf");
  32. FileOutputStream out=null;
  33. InputStream input=null;
  34. try{
  35. //判断文件是否存在
  36. File f=new File(fileepath);
  37. if(!f.exists()){
  38. f.createNewFile();
  39. }
  40. Map<String, Object> parameters=new HashMap<String, Object>();
  41. parameters.put("title", "张散弹");
  42. parameters.put("head", "nininn好好好好");
  43. //模板文件
  44. String ctxpathIreport=request.getSession().getServletContext().getRealPath("jasper/report3.jasper");
  45. File reportFile=new File(ctxpathIreport);
  46. // JasperReport jasperReport=(JasperReport)JRLoader.loadObject(reportFile);
  47. // JasperPrint jasperPrint=JasperFillManager.fillReport(jasperReport, parameters);
  48. input = new FileInputStream(reportFile);
  49. out=new FileOutputStream(f);
  50. //前面两个都是流 parameters 设置页面上的数据 最后一个数据源为空
  51. JasperRunManager.runReportToPdfStream(input, out, parameters, new JREmptyDataSource());
  52. //JasperExportManager.exportReportToPdfFile(jasperPrint,fileepath);
  53. }catch (Exception e) {
  54. e.printStackTrace();
  55. }finally{
  56. //关闭流
  57. try {
  58. out.close();
  59. } catch (IOException e) {
  60. e.printStackTrace();
  61. }
  62. try {
  63. input.close();
  64. } catch (IOException e) {
  65. e.printStackTrace();
  66. }
  67. }
  68. }
  69. @RequestMapping(value="/cs",method=RequestMethod.GET)
  70. public void createFilePdfs(HttpServletRequest request){
  71. //路径动态录入需要生产的pdf文件位置
  72. String fileepath=request.getSession().getServletContext().getRealPath("template/repConReport.pdf");
  73. //String fileepaths=request.getSession().getServletContext().getRealPath("template/s.html");
  74. try{
  75. //判断文件是否存在
  76. File f=new File(fileepath);
  77. if(!f.exists()){
  78. f.createNewFile();
  79. }
  80. //自定义数据源
  81. Map<String, Object> parameters=new HashMap<String, Object>();
  82. parameters.put("title", "张散弹");
  83. parameters.put("head", "nininn好好好好");
  84. List<Map<String, Object>> list=new ArrayList<Map<String,Object>>();
  85. list.add(parameters);
  86. list.add(parameters);
  87. list.add(parameters);
  88. JRDataSource data= new JRBeanCollectionDataSource(list);
  89. // File reportFile=new File(reportFilePath);
  90. //模板文件
  91. String ctxpathIreport=request.getSession().getServletContext().getRealPath("jasper/contract.jasper");
  92. File reportFile=new File(ctxpathIreport);
  93. //实际中编译报表很耗时,采用Ireport编译好的报表
  94. JasperReport jasperReport=(JasperReport)JRLoader.loadObject(reportFile);
  95. //填充数据
  96. JasperPrint jasperPrint=JasperFillManager.fillReport(jasperReport, parameters, data);
  97. //导出pdf文件
  98. JasperExportManager.exportReportToPdfFile(jasperPrint,fileepath);
  99. //JasperExportManager.exportReportToHtmlFile(jasperPrint, "");
  100. }catch (Exception e) {
  101. e.printStackTrace();
  102. }
  103. }
  104. @RequestMapping(value="/csd",method=RequestMethod.GET)
  105. public void createFilePdfsd(HttpServletRequest request){
  106. //路径动态录入需要生产的pdf文件位置
  107. String fileepath=request.getSession().getServletContext().getRealPath("template/repConReport.pdf");
  108. try{
  109. //判断文件是否存在
  110. File f=new File(fileepath);
  111. if(!f.exists()){
  112. f.createNewFile();
  113. }
  114. //自定义数据源
  115. Map<String, Object> parameters=new HashMap<String, Object>();
  116. //获取Javabean list
  117. List<UserInfo> userList= UserInfo.getListUserInfo();
  118. //数据源为javabean
  119. JRDataSource data= new JRBeanCollectionDataSource(userList);
  120. //设置数据
  121. parameters.put("beans", data);
  122. //模板文件
  123. String ctxpathIreport=request.getSession().getServletContext().getRealPath("jasper/report5.jasper");
  124. File reportFile=new File(ctxpathIreport);
  125. //实际中编译报表很耗时,采用Ireport编译好的报表
  126. JasperReport jasperReport=(JasperReport)JRLoader.loadObject(reportFile);
  127. //填充数据
  128. JasperPrint jasperPrint=JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
  129. //导出pdf文件
  130. JasperExportManager.exportReportToPdfFile(jasperPrint,fileepath);
  131. }catch (Exception e) {
  132. e.printStackTrace();
  133. }
  134. }
  135. }

这样中文就设置好了 打印出来中文也有了


声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号