how to print jasper report in Eclipse RCP using its print option?

本小妞迷上赌 提交于 2019-12-07 07:31:10

问题


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 :

  1. replace the ViewerComposite (i.e. com.jasperassistant.designer.viewer.ViewerComposite.ViewerComposite) by SWT/AWT composite and JRViewer (net.sf.jasperreports.view.JRViewer) first.
  2. set the generated JasperPrint document onto the JRViewer object.
  3. add the JRViewer object onto the ContentPane of this SWT/AWT composite.
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!