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引用

转载于:https://www.cnblogs.com/zhuqianchang/p/7274180.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值