Tutorial :Export Crystal reports to PDF in java


Can anyone guide me on how to export crystal reports into PDF in java?

I am using Crystal Report Server XI.

Thanks in advance.


I've documented my spike test for the SAP Crystal Reports for Java runtime components â€" Java Reporting Component (JRC) here:


I was using Business Objects 4.0, and probably the most important thing was to get the Java library â€" download ‘SAP Crystal Reports for Java runtime components â€" Java Reporting Component (JRC)’ from:


There are a lot of samples on the web to look at â€" you might find something to help here: http://wiki.sdn.sap.com/wiki/display/BOBJ/Java+Reporting+Component++SDK+Samples

A good example to start with is “JRC EXPORT REPORT”: http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40d580ce-bd66-2b10-95b0-cc4d3f2dcaef

In my case I didn't need a server - I just used the JAR files, the RPT file, the database and my CRConfig.xml file:

<?xml version="1.0" encoding="utf-8"?>  <CrystalReportEngine-configuration>      <reportlocation>..</reportlocation>      <timeout>0</timeout>      <ExternalFunctionLibraryClassNames>          <classname></classname>      </ExternalFunctionLibraryClassNames>  </CrystalReportEngine-configuration>  


This is more for an automated process.

First get the raw byte export from the crystal:

 ReportClientDocument reportClientDoc = new ReportClientDocument();      reportClientDoc.open(sourceReportFile, OpenReportOptions._openAsReadOnly);        ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) reportClientDoc.getPrintOutputController().export(ReportExportFormat.PDF);        //Release report.      reportClientDoc.close();  

Then Create a new file that will contain the exported result.

    File file = new File(exportedFileName);        FileOutputStream fileOutputStream = new FileOutputStream(file);        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(byteArrayInputStream.available());      int x = byteArrayInputStream.read(byteArray, 0, byteArrayInputStream.available());        byteArrayOutputStream.write(byteArray, 0, x);      byteArrayOutputStream.writeTo(fileOutputStream);        //Close streams.      byteArrayInputStream.close();      byteArrayOutputStream.close();      fileOutputStream.close();  


You should have Java edition of Crystal Reports SDK. The Book Crystal Reports XI Official Guide provides necessary details.

You can use any one of the PDF Library in Java to do that. As far as I know, there are two most popular libraries like iText and Apache's PDFBox

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »