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=\"<[EMAIL PROTECTED]>\"");
 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: "+ "<[EMAIL PROTECTED]>");
    //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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to