zoukankan      html  css  js  c++  java
  • jasperreports-5.6 + jaspersoftstudio-5.6 生成pdf 文件中文无法正常显示问题

    jrxml字段属性设置:

    <textElement>
       <font fontName="宋体" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
    </textElement>

    在工程lib中引入itextasian-1.5.2.jar文件,注意该文件的目录结构为com/lowagie/text/pdf/fonts/*,最新的itext-asian.jar包不是该结构无法正常使用,

    JAVA示例代码:

        /****数据库连接****/
        public static Connection getConnection() {
            Connection conn = null;
            String driver = "net.sourceforge.jtds.jdbc.Driver";
            String url = "jdbc:jtds:sqlserver://127.0.0.1:1433/CODE-WH";
            try {
                Class.forName(driver);
                conn = DriverManager.getConnection(url,"sa", "123");
                return conn;
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            return null;
        }
    
        public static void main(String[] args) throws Exception {
            String fileName = "D:/Coffee.jrxml";
            long startTime = System.currentTimeMillis();
            // 将报表的定义文件*.jrxml编译成*.jasper文件
            String jasperFile = JasperCompileManager.compileReportToFile(fileName);
            // 向*.jasper文件中填充数据,这一步将生产出*.jrprint文件
            String jrprintFile = JasperFillManager.fillReportToFile(jasperFile,
                    null, getConnection());
            System.out.println("jrprintFile=="+jrprintFile);
            // 将.jrprint文件转换成HTML格式
            JasperExportManager.exportReportToHtmlFile(jrprintFile);
            // 将.jrprint文件转换成PDF格式
            JasperExportManager.exportReportToPdfFile(jrprintFile);
            // 将.jrprint文件转换成XML格式
            //JasperExportManager.exportReportToXmlFile(jrprintFile, false);
            // 将.jrprint文件转换成XLS格式(即Excel文件),需要用到POI类库.
            
            File sourceFile = new File(jrprintFile);
            JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(sourceFile);
            File destFile = new File(sourceFile.getParent(), jasperPrint.getName()
                    + ".xls");
            JRXlsExporter exporter = new JRXlsExporter();
            exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
            exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));
            SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
            configuration.setOnePagePerSheet(false);
            exporter.setConfiguration(configuration);
            exporter.exportReport();
            
            long endTime = System.currentTimeMillis();
            long time = (endTime - startTime) / 1000;
            System.out.println("success with " + time + " s");
        }
  • 相关阅读:
    蚂蚁金服SOFAMesh在多语言上的实践
    2018第48周日
    git只拉取github部分代码的方法
    深入理解brew link命令
    openssl/ssl.h file not found
    react热加载失败
    pycharm批量清楚pyc、$py.class文件
    Hash history cannot PUSH the same path; a new entry will not be added to the history stack
    JavaScript indexOf() 方法,获取元素的位置;Object.keys()获取对象的所有key的数组
    JavaScript删除数组里的某个元素
  • 原文地址:https://www.cnblogs.com/101key/p/4003670.html
Copyright © 2011-2022 走看看