论坛首页 Java企业应用论坛

jpivot中输出pdf打印汉字、excel导出中文方法

浏览 7135 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-05-18  

jpivot是目前用得最多得OLAP展现工具,pentaho,spagoBI,openi等都是用他来做展现,

jpivot中pdf打印输出中文

1.升级com.tonbeller.jpivot.print.PrintServlet文件到JPivot1.6.0以上,如果不想升级就修改PrintServlet

在init方法中增加以下语句.  

java 代码 
  1. public void init(ServletConfig config) throws ServletException {   
  2.     super.init(config);   
  3.     try {   
  4.       // set base FOP FONT directory.  The font config  stuff will be looked for here   
  5.       Configuration.put("fontBaseDir", config.getServletContext().getRealPath("/WEB-INF/jpivot/print/"));   
  6.       // get the physical path for the config file   
  7.       String fopConfigPath = config.getServletContext().getRealPath("/WEB-INF/jpivot/print/userconfig.xml");   
  8.       // load the user proerties, contining the CustomFont font.   
  9.       new Options(new File(fopConfigPath));   
  10.   
  11.     } catch (FOPException e) {   
  12.       e.printStackTrace();   
  13.       logger.info("FOP user config file not loaded");   
  14.     } catch (Exception e) {   
  15.       e.printStackTrace();   
  16.       logger.info("FOP user config file not loaded");   
  17.     }   
  18.   }   
  19.   

2.在WEB-INF\jpivot\print目录下建立userconfig.xml文件。内容如下:(仅配置黑体)

xml 代码
  1. <configuration>  
  2.   
  3. <fonts>  
  4.   
  5. <font metrics-file="simhei.xml" kerning="yes" embed-file="simhei.ttf">  
  6.   
  7. <font-triplet name="SimHei" style="normal" weight="normal"/>  
  8.   
  9. <font-triplet name="SimHei" style="normal" weight="bold"/>  
  10.   
  11. <font-triplet name="SimHei" style="italic" weight="normal"/>  
  12.   
  13. <font-triplet name="SimHei" style="italic" weight="bold"/>  
  14.   
  15. font>  
  16.   
  17. fonts>  
  18.   
  19. configuration>  
  20.   

3. 下载Apache的FOP包,解开fop-0.20.5.jar,启用cmd,并到它的目录中,执行:

java org.apache.fop.fonts.apps.TTFReader -ttcname SimHei C:\WINDOWS\Fonts\simhei.ttf simhei.xml

然后就会生成需要的两个字体描述文件:simhei.xml

4. 将simhei.xml,以及simhei.ttf文件放到WEB-INF\jpivot\print目录下。

5. 修改WEB-INF\jpivot\table目录下的fo_mdxtable.xsl文件,把所有的font-family对应成SimHei

 jpivot excel导出中文

Excel中不支持UTF-8, Excel输出对应的xsl文件是:../web-inf/jpivot/table目录下的xls_mdxtable.xsl

只要这个文件的encoding换为GBK就可以了.

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics