Zip Jasper reports

302 views Asked by At
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();

I am trying to zip multiple jasper reports. I can zip one report but not been able to zip multiple reports. I am using Java list to add same Jasperprint just to test, whether this can zip more then one report.

0

There are 0 answers