jasper打印文件出現空白頁面


EG:打印文件結果打印出一片空白  

原因:使用了null的數據源而不是JREmptyDataSource

 

以下為正確代碼

public <T> List<JasperPrint> createJasperPrint_1(List<T> list,
Map<String, Object> imgMap, Map<String, Object> pathMap) {
List<JasperPrint> printList = new ArrayList<JasperPrint>();
if (pathMap != null) {
try {
for (String kn : pathMap.keySet()) {
ServletContext context = ServletActionContext
.getRequest().getSession().getServletContext();
String file = context.getRealPath(String.valueOf(pathMap.get(kn)));
JasperReport report = (JasperReport) JRLoader
.loadObject(file);
JRDataSource source = new JRBeanCollectionDataSource(
list);

JasperPrint print = new JasperPrint();
//如果數據集為空 則應該使用JREmptyDataSource 否則會打印空白頁面
if (list == null) {
print = JasperFillManager.fillReport(
report, imgMap, new net.sf.jasperreports.engine.JREmptyDataSource());
} else {
print = JasperFillManager.fillReport(
report, imgMap, source);
}
if (print != null)
printList.add(print);
}

} catch (JRException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
return printList;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM