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

那年仲夏 提交于 2019-12-05 16:59:22
yayayokoho3

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