Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Crystal Report and Swing application

We are evaluating crystal report and other reporting tools to use in our application.

The application is going to be developed in Java Swing. From this application, crystal report needs to be displayed. So, Is there possibility we can integrate crystal report with our application. The input data is going to be in XML and output should be in PDF.

We are expecting some thing like this.

Crystal report should provide Java APIs to integrate with our application. API should take XML as an Input data and crystal report template file(.rpt). It should return the output in pdf file.

If this is possible, can you tell me where I can get the sample codes?

Thanks,

Makesh

Former Member
replied

Snippet for JRC XML "push":

ReportClientDocument rcd = new ReportClientDocument();
/*
 * Open and read CR Report and XML Data and Schema Files.  
 */
rcd.open("reports/test_xml.rpt", 0);
FileInputStream fin = new FileInputStream("reports/new_test_data.xsd");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] bytes = new byte[1024];
for(;;) {
	int count = fin.read(bytes);
	if(count < 0)
		break;
	baos.write(bytes, 0, count);
}
final byte[] xsdBytes = baos.toByteArray();
fin.close();

fin = new FileInputStream("reports/new_test_data.xml");
baos = new ByteArrayOutputStream();
bytes = new byte[1024];
for(;;) {
	int count = fin.read(bytes);
	if(count < 0)
		break;
	baos.write(bytes, 0, count);
}
final byte[] xmlBytes = baos.toByteArray();
fin.close();

/*
 * Inject XML data into CR Report using IXMLDataSet into
 * table "schema1/People".
 */
IXMLDataSet xml_ds = new IXMLDataSet() {
	private IByteArray xmlData = null;
	public void setXMLData(IByteArray xmlData) {
		this.xmlData = xmlData;
	}
	public IByteArray getXMLData() {
		return this.xmlData;
	}
	private IByteArray xmlSchema = null;
	public void setXMLSchema(IByteArray xmlSchema){
		this.xmlSchema = xmlSchema;
	}
	public IByteArray getXMLSchema() {
		return this.xmlSchema;
	}

};

xml_ds.setXMLData(new IByteArray() {
	public void fromString(String arrayValue){}
	public String toString() { return ""; }
	public byte[] getBytes() { return xmlBytes; }
});

xml_ds.setXMLSchema(new IByteArray() {
	public void fromString(String arrayValue){}
	public String toString() { return ""; }
	public byte[] getBytes() { return xsdBytes; }
});

rcd.getDatabaseController().setDataSource(xml_ds, "schema1/People", "schema1/People");

Sincerely,

Ted Ueda

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question