Zip Jasper报道

时间:2016-12-30 22:26:49

标签: java zip zipoutputstream

zipfile = new ZipOutputStream(response.getOutputStream());
response.setHeader("Content-Disposition", "attachment; filename=\"" + "myReport.zip\";");
response.setContentType("application/zip");
List<JasperPrint> print2 = new ArrayList<JasperPrint>();
print2.add(print);
try {      
    for (int j = 0; j < 5; j++) {
    byte[] pdfAsBytes;   
    byte[] buffer = new byte[1024];
    pdfAsBytes =  JasperExportManager.exportReportToPdf(print2.get(j));
    ByteArrayInputStream fis = new ByteArrayInputStream(pdfAsBytes);
    zipfile.putNextEntry(new ZipEntry(print2.get(j).getName()+".pdf"));
    int length;
    while ((length = fis.read(buffer,0,1024)) > 0) {
        zipfile.write(buffer, 0, length);
    }
    zipfile.closeEntry();
    // close the InputStream
    fis.close();
}  
zipfile.close();

我正在尝试压缩多个jasper报告。我可以压缩一个报告,但无法压缩多个报告。我正在使用Java列表添加相同的Jasperprint来测试,这是否可以压缩多个报告。

0 个答案:

没有答案