java与jasper模板_ireport中使用java进行pdf转化,jasper作为模板

/**

* 导出pdf

* @param list

*/

public void pdfExport(List list) {

File file = new File("E:\\1.jasper");

JasperReport report = null;

JasperPrint jasperPrint = null;

try {

report = (JasperReport) JRLoader.loadObject(file);

} catch (JRException e1) {

e1.printStackTrace();

}

JRDataSource jrDataSource = new JRBeanCollectionDataSource(list);

Map params = new HashMap();

if(report!=null) {

try {

jasperPrint = JasperFillManager.fillReport(report, params, jrDataSource);

} catch (JRException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

JRPdfExporter pdfExporter = new JRPdfExporter();

pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

pdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"E:\\1.pdf");

try {

pdfExporter.exportReport();

} catch (JRException e) {

e.printStackTrace();

}

}

这里List里封装的是实体类,jasper是已经设计好的模板,模板就是根据实体类的属性设置的。这样通过调用相关方法,把List里的数据添加到模板中的相应位置,然后转成pdf文件。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值