This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Problem while generating PDF from Servlet using Jasper Report

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!