permaculture playing cards*
The moose likes Other Java Products and Servers and the fly likes Problem while generating PDF from Servlet using Jasper Report Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Problem while generating PDF from Servlet using Jasper Report" Watch "Problem while generating PDF from Servlet using Jasper Report" New topic
Author

Problem while generating PDF from Servlet using Jasper Report

Vijay Arora
Greenhorn

Joined: Jun 25, 2007
Posts: 19
I m facing problem while generating PDF using Japer report. below is the servlet code that is handlig client request.

response.setContentType("application/pdf");
response.setHeader("Content-disposition","attachment; filename=\""+ReportName+""+currDate+".pdf \"");
response.getOutputStream().write(optionHoldingsReport.generateOptionHoldingsReport(jrxmlPath));
response.flushBuffer();

And generateOptionHoldingsReport method returns byte array and i am writiing this byte array to the outputstream..below is code of this method.

public byte[] generateOptionHoldingsReport(String jrxmlPath) throws Exception
{
logger.debug("[OptioHoldingsReport - Inside generateOptioHoldingsReport() :] ");
logger.info("jrxmlPath:"+jrxmlPath);
List dataList=new ArrayList();
byte[] reportData=null;
HashMap parameters = new HashMap();
JasperPrint jasperPrint;
try
{
logger.info("ReportConstants.HEADER_IMAGE_PATH:"+ReportConstants.HEADER_IMAGE_PATH);
parameters.put("imagePath", ReportConstants.HEADER_IMAGE_PATH);
dataList= populateData();

JasperReport jasperReport = JasperManager.loadReport(jrxmlPath);
logger.info("jasperReport: "+jasperReport);
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(dataList);
logger.info("ds: "+ds);
reportData = JasperRunManager.runReportToPdf(jasperReport,parameters, ds);
logger.info("reportData: "+reportData);
//jasperPrint = JasperFillManager.fillReport(jasperReport,parameters, ds);
//JasperExportManager.exportReportToPdfStream(jasperPrint,servletOutputStream);
logger.info("Exit");
}
catch(Exception e)
{
logger.error("[ OptioHoldingsReport - generateOptioHoldingsReport ():] Exception is "+e.getMessage());
}
return reportData;
}

this api is not throwing any exeption but its not printing below line in logger. and adobe reader is showing error that it can not open pdf file due to unsupported type format.
logger.info("reportData: "+reportData);



What change i should make to generate proper PDF file.
Please suggest.





vijay arora
 
wood burning stoves
 
subject: Problem while generating PDF from Servlet using Jasper Report
 
Similar Threads
Problem in passing JRBeanCollectionDataSource as parameter to jasperreport
Jasper Reports with hibernate
Problem in passing JRBeanCollectionDataSource as parameter to jasperreport
Struts and jasper report
Same Jasper Report keeps opening