zoukankan      html  css  js  c++  java
  • JasperReport生成PDF文件

    前言

    最近公司项目中需要使用JasperReport报表生成工具,使用6.2版本。用Jaspersoft Studio工具画jasper模板,模板就不附上了。

    所需JAR包

    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>6.2.0</version>
    </dependency>
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itext-asian</artifactId>
        <version>1.5.2</version>
    </dependency>

    生成PDF

    public static void main(String[] args) throws Exception {
    
        String fileName = "D:\test.jasper";
        String outFileName = "D:\test.pdf";
        HashMap map = new HashMap();
        JasperPrint print = JasperFillManager.fillReport(fileName, map, new JREmptyDataSource());
        JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
        exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileName);
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
        exporter.exportReport();
        System.out.println("Created file: " + outFileName);
    
    }

    常见错误

    1.net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font :

    pdfFontName : STSong-Light

    pdfEncoding : UniGB-UCS2-H

    isPdfEmbedded : false

    出现上述错误提示原因:缺少iTextAsian.jar引用

  • 相关阅读:
    【数学】【AOJ-614】座位安排
    【乱搞】【AOJ-611】消失的5,8,9
    redis 与session
    Nginx 与 tomcat 部署网站
    linux 进程在后台执行
    印象笔记
    consul 小結
    spring boot 使用拦截器,注解 实现 权限过滤
    Springcloud/Springboot项目绑定域名,使用Nginx配置Https
    spring boot 登录认证
  • 原文地址:https://www.cnblogs.com/zhuqianchang/p/7274180.html
Copyright © 2011-2022 走看看