Skip to Content
0
Former Member
Apr 01, 2011 at 11:54 AM

Export pdf from crystal report

16 Views

Hi,

I am using crystal report. Now I want to open this report in pdf format. I tried some coding but it throws some exception, if you know please help me... Below is the code which I was used,

ReportClientDocument clientDoc = new ReportClientDocument();

clientDoc.open(rptname, ReportExportFormat._PDF);

clientDoc.open("rpt/"rptname".rpt", ReportExportFormat._PDF);

Connecting Database through crystal report .logon(u201Cusernameu201D, u201Cpasswordu201D); .setCurrentValue(u201Cu201D, u201CNameu201D,u201Danandu201D);

clientDoc.getDatabaseController().logon(ConfigurationManager.getInstance().getPropertyValue(WebConstants.REPORT_SERVER_DBUSER),ConfigurationManager.getInstance().getPropertyValue(WebConstants.REPORT_SERVER_DBPASSWORD));

HashMap params = ReportService.getPDFParams(reportParams);

Set keySet = params.keySet();

for(Iterator it=keySet.iterator();it.hasNext();){

String key = (String)it.next();

String value = (String)params.get(key);

clientDoc.getDataDefController().getParameterFieldController().setCurrentValue("", key,value);

}

ByteArrayInputStream bais = (ByteArrayInputStream) clientDoc.getPrintOutputController().export(ReportExportFormat.PDF);

int size = bais.available();

byte[] barray = new byte[size];

FileOutputStream fos = new FileOutputStream(new File(exportFileName));

ByteArrayOutputStream baos = new ByteArrayOutputStream(size);

int bytes = bais.read(barray, 0, size);

baos.write(barray, 0, bytes);

baos.writeTo(fos);

clientDoc.close();

bais.close();

baos.close();

fos.close();

Please update me as soon as possible..