Question: Can i export crystal report to pdf using java standalone program (not using web application or server).
Requirement : I want to export crystal report to pdf file using standalone java application. I am able to do so using SAP Crystal Report 2013 on my desktop. For java i have downloaded crjava-runtime_12.2.220 library and using following code.
import com.crystaldecisions.reports.sdk.*; import com.crystaldecisions.sdk.occa.report.lib.*; import com.crystaldecisions.sdk.occa.report.exportoptions.*; //Java imports. import java.io.*; public class JRCExportReport { static final String REPORT_NAME = "C:/abc.rpt"; static final String EXPORT_FILE = "C:/abc.pdf"; public static void main(String[] args) { try { //Open report. ReportClientDocument reportClientDoc = new ReportClientDocument(); reportClientDoc.open(REPORT_NAME, ReportExportFormat._PDF); //NOTE: If parameters or database login credentials are required, they need to be set before. //calling the export() method of the PrintOutputController. //Export report and obtain an input stream that can be written to disk. //See the Java Reporting Component Developer's Guide for more information on the supported export format enumerations //possible with the JRC. ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream)reportClientDoc.getPrintOutputController().export(ReportExportFormat.PDF); //Release report. reportClientDoc.close(); //Use the Java I/O libraries to write the exported content to the file system. byte byteArray[] = new byte[byteArrayInputStream.available()]; //Create a new file that will contain the exported result. File file = new File(EXPORT_FILE); 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(); System.out.println("Successfully exported report to " + EXPORT_FILE); } catch(ReportSDKException ex) { ex.printStackTrace(); } catch(Exception ex) { ex.printStackTrace(); } } } Getting following exception on line (reportClientDoc.open(REPORT_NAME, ReportExportFormat._PDF);): log4j:WARN No appenders could be found for logger (com.crystaldecisions.reports.common.engine.config). log4j:WARN Please initialize the log4j system properly. com.crystaldecisions.sdk.occa.report.lib.ReportSDKException: Index: 0, Size: 0---- Error code:-2147467259 Error code name:failed at com.businessobjects.reports.sdk.JRCCommunicationAdapter.<init>(SourceFile:285) at com.businessobjects.sdk.erom.jrc.a.<init>(SourceFile:43) at com.businessobjects.sdk.erom.jrc.ReportAgentFactory.createAgent(SourceFile:46) at com.crystaldecisions.proxy.remoteagent.RemoteAgent$a.<init>(SourceFile:703) at com.crystaldecisions.proxy.remoteagent.RemoteAgent.a(SourceFile:662) at com.crystaldecisions.proxy.remoteagent.RemoteAgent.a(SourceFile:632) at com.crystaldecisions.sdk.occa.report.application.ClientDocument.if(SourceFile:504) at com.crystaldecisions.sdk.occa.report.application.ClientDocument.open(SourceFile:669) at com.crystaldecisions.reports.sdk.ReportClientDocument.open(SourceFile:80) at JRCExportReport.main(JRCExportReport.java:33) Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source) at com.crystaldecisions12.reports.dataengine.h.if(SourceFile:2219) at com.crystaldecisions12.reports.dataengine.h.i(SourceFile:255) at com.crystaldecisions12.reports.dataengine.h.a(SourceFile:2065) at com.crystaldecisions12.reports.dataengine.h.try(SourceFile:1878) at com.crystaldecisions12.reports.reportdefinition.ReportDocument.a(SourceFile:2378) at com.crystaldecisions12.reports.reportdefinition.ReportDocument.a(SourceFile:1716) at com.crystaldecisions12.reports.common.Document.a(SourceFile:689) at com.crystaldecisions12.reports.common.Document.do(SourceFile:651) at com.crystaldecisions12.reports.reportdefinition.ReportDocument.a(SourceFile:2325) at com.crystaldecisions12.reports.reportdefinition.ReportDocument.a(SourceFile:1716) at com.crystaldecisions12.reports.common.Document.a(SourceFile:521) at com.crystaldecisions12.reports.common.Document.loadDocument(SourceFile:437) at com.crystaldecisions12.reports.reportdefinition.ReportDocument.loadDocument(SourceFile:1516) at com.crystaldecisions12.reports.reportdefinition.ReportDocument.LoadDocument(SourceFile:1479) at com.businessobjects.reports.reportconverter.v12.c.a(SourceFile:59) at com.businessobjects.reports.reportconverter.v12.V12SaveLoader.a(SourceFile:159) at com.businessobjects.reports.loader.ReportLoader.a(SourceFile:205) at com.businessobjects.reports.sdk.JRCReportLoader.a(SourceFile:137) at com.businessobjects.reports.sdk.JRCReportLoader.a(SourceFile:76) at com.businessobjects.reports.sdk.requesthandler.ReportDocumentRequestHandler.a(SourceFile:137) at com.businessobjects.reports.sdk.JRCCommunicationAdapter.<init>(SourceFile:228) ... 9 more