Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Problem while generating PDF from Servlet using Jasper Report

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.setHeader("Content-disposition","attachment; filename=\""+ReportName+""+currDate+".pdf \"");

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() :] ");"jrxmlPath:"+jrxmlPath);
List dataList=new ArrayList();
byte[] reportData=null;
HashMap parameters = new HashMap();
JasperPrint jasperPrint;
parameters.put("imagePath", ReportConstants.HEADER_IMAGE_PATH);
dataList= populateData();

JasperReport jasperReport = JasperManager.loadReport(jrxmlPath);"jasperReport: "+jasperReport);
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(dataList);"ds: "+ds);
reportData = JasperRunManager.runReportToPdf(jasperReport,parameters, ds);"reportData: "+reportData);
//jasperPrint = JasperFillManager.fillReport(jasperReport,parameters, ds);
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."reportData: "+reportData);

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

The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic