cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate PDF report directly instead of RPT report by using JRC ?

Former Member
0 Kudos

Hi,

Good Day !

How to generate PDF report directly instead of RPT report by using Crystal Reports XI Release 2 Java Reporting Component (JRC) in desktop (Swing thick-client) ?

My GUI program will generate a RPT report, then i can export to PDF file, this is ok, no problem.

BUT

i want it direct to generate a PDF report, not a RPT report.

The code like below (2 java files)

ClassA.java

:

:

ReportClientDocument reportClientDoc = new ReportClientDocument();

reportClientDoc.open(XXX, 0);

ParameterFieldController paramFieldController = reportClientDoc.getDataDefController().getParameterFieldController();

paramFieldController.setCurrentValue("", "XXX", DomainClass.getXXX());

new ReportViewerFrame(reportClientDoc);

:

:

// End of ClassA.java

// Begin ReportViewerFrame.java

public class ReportViewerFrame extends JFrame

:

:

//Initial window frame properties.

private final int XPOS = 80;

private final int YPOS = 60;

private final int WIDTH = 760;

private final int HEIGHT = 550;

private ReportViewerBean reportViewer = new ReportViewerBean();

private ReportClientDocument reportClientDoc = new ReportClientDocument();

public ReportViewerFrame(ReportClientDocument reportClientDoc) throws Exception

{

//Initialize frame properties.

this.setResizable(true);

this.setLocation(XPOS, YPOS);

this.setSize(WIDTH, HEIGHT);

this.setTitle("Crystal Report Java Viewer");

//Add GUI components to the frame including the ReportViewerBean.

addComponents();

//Add GUI listeners to the frame.

addListeners();

//Set the report that the ReportViewerBean will display.

this.reportClientDoc = reportClientDoc;

reportViewer.setReportSource(reportClientDoc.getReportSource());

reportViewer.init();

reportViewer.start();

//Display the frame.

this.setVisible(true);

}

How to set the export option to PDF base on existing code ?

Where can i download this package/jar ?

regards

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Please find a console app that you can extend it to a JFrame app by importing the relevant swing package:

//Crystal Java Reporting Component (JRC) imports.
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 ExportReport {

	static final String REPORT_NAME = "ExportReport.rpt";
	static final String EXPORT_FILE = "C:\\myExportedReport.pdf";
	
	public static void main(String[] args) {

		try {

			//Open report.			
			ReportClientDocument reportClientDoc = new ReportClientDocument();			
			reportClientDoc.open(REPORT_NAME, 0);
			
			//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();
						
		}

	}

}

As to the relevant jar(s) deployment refer to this link (Java Reporting Component Configuration):

http://devlibrary.businessobjects.com/BusinessObjectsXIR2SP2/en/en/JRC_SDK/jrc_java_dg_doc/doc/jrcsd...

Cheers

aasavaribhave
Advisor
Advisor
0 Kudos

Hi,

Please refer to the JSP sample at the following link for exporting to PDF using JRC. You can easily convert the JSP code into Java Thick client app.

https://boc.sdn.sap.com/node/5793

Thanks

Aasavari