问题
My question : I have a ViewerComposite in Eclipse RCP application which displays Jasper Report (*.jrxml) integrated into it. The report displayed in this ViewerComposite can be exported as PDF,RTF,XML,jrxml,HTML,CSV, etc. Everything is fine except I can not print this report by using the print option provided at top of ViewerComposite in GUI. How can I print the reports by using my default printer by using print option of the report viewer. Rem: I can print jasper report by using the print option of jasper report viewer composite in Oracle JDeveloper Projects without adding any more codes(by default).
回答1:
The best way for me to make my Jasper Reports in Eclipse RCP application was as follows :
- replace the ViewerComposite (i.e. com.jasperassistant.designer.viewer.ViewerComposite.ViewerComposite) by SWT/AWT composite and JRViewer (net.sf.jasperreports.view.JRViewer) first.
- set the generated JasperPrint document onto the JRViewer object.
- add the JRViewer object onto the ContentPane of this SWT/AWT composite.
- run the report and check printing and exporting the report data into allowed formats ie.(.PDF,.ODT,.docx,.jrxml,.jasper,.xml,.html,.xls etc); all will work.
The details code for this is as follows :
//generate the jaspser print document
JasperPrint jprint = generateReport(id, nepFromDate, nepToDate);
//initialize JRViewer object
JRViewer jasperviewer = new JRViewer(jprint);
//add the SWT_AWT compposite for SWING contents of GUI
final Composite swtAwtComposite = new Composite(comTBReport, SWT.EMBEDDED);
swtAwtComposite.setBounds(10, 0, 767, 600);
Frame frame = SWT_AWT.new_Frame(swtAwtComposite);
Panel panel = new Panel();
frame.add(panel);
panel.setLayout(new BorderLayout(0, 0));
JRootPane rootPane = new JRootPane();
rootPane.setSize(767, 600);
panel.add(rootPane);
//Define a container yourself
Container c = rootPane.getContentPane();
//Add the JRViewer object onto the container to render in GUI
c.add(jasperviewer);
来源:https://stackoverflow.com/questions/8487451/how-to-print-jasper-report-in-eclipse-rcp-using-its-print-option