You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Sohail Aslam <so...@techlogix.com> on 2005/10/04 05:49:44 UTC

download multiple JasperReport generated PDF

I am using a Tapestry service to provide download of Jasperreports 
generated PDF reports. Here is the code that generates the report (based 
on code available on this list):

=====================================

  byte[] pdfData = JasperExportManager.exportReportToPdf(jasperPrint);

  HttpServletResponse response = cycle.getRequestContext().getResponse();
  response.setContentType("application/pdf");
  response.setHeader("Content-Disposition",
                         "attachment; filename=\""
                         +tUtil.extractFilename(fileBasename) +
                         ".pdf\"");
  response.setContentLength((int) pdfData.length);

  ServletOutputStream out = response.getOutputStream();
  out.write(pdfData, 0, pdfData.length);
  out.flush();
  out.close();

=======================================

This works for a single PDF report. I need to provide download of 
multi-part report. I tried multipart MIME using the following code:

========================================
  HttpServletResponse response = cycle.getRequestContext().getResponse();
  ServletOutputStream out = response.getOutputStream();

  response = cycle.getRequestContext().getResponse();
  response.setHeader("Content-Type", "Multipart/mixed; 
boundary=MIME_boundary; 
type=application/pdf;start=\"<in...@arabiandreams.ae>\"");
  out.println("--MIME_boundary");

  byte[] pdfData;
  int i;
  for(i=0; i< reportFile.length; i++ )
  {
   // add context path to get the complete filesystem path
     String fileBasename = tUtil.getContextRealPath(cycle) +
        System.getProperty("file.separator") + reportFile[i];
     logger.debug("generateMultiPageReport: processing "+reportFile[i]);
     jasperPrint = JasperFillManager.fillReport(fileBasename+".jasper",
                       params, ds);
     pdfData = JasperExportManager.exportReportToPdf(jasperPrint);

     out.println("Content-Disposition: "+
                   "attachment; filename=\"" +
                   tUtil.extractFilename(fileBasename) +
                   ".pdf\"");
     out.println("Content-Type: "+"application/pdf");
     out.println("Content-ID: "+ "<in...@arabiandreams.ae>");
     //response.setContentLength( (int) pdfData.length);
     out.write(pdfData, 0, pdfData.length);
     out.println("--MIME_boundary;");
   }
   out.flush();
   out.close();
============================================================

Upon download, the PDF code simply appears raw in the browser. I tried
Content-Type: Multipart/Related but got the same result.

How can I download multiple PDFs, each with its own Content-Disposition: 
and have the browser present multiple "Save as" dialogs? Mail readers 
like Thurderbird know how to handle multipart messages; I have a hunch 
that browsers may not be able to. For the moment I have multiple submit 
buttons each tied to a PDF report download.  I am using Tapestry 3.0.3.

Sohail Aslam
sohail dot aslam at gmail dot com


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org