如何使用其打印选项在Eclipse RCP中打印jasper报告? [英] how to print jasper report in Eclipse RCP using its print option?

查看:66
本文介绍了如何使用其打印选项在Eclipse RCP中打印jasper报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:我在Eclipse RCP应用程序中有一个ViewerComposite,其中显示了集成到其中的Jasper Report(* .jrxml).此ViewerComposite中显示的报告可以导出为PDF,RTF,XML,jrxml,HTML,CSV等.一切都很好,但是我无法使用GUI的ViewerComposite顶部提供的打印选项来打印此报告.如何使用报表查看器的打印选项使用默认打印机来打印报表. Rem:我可以使用Oracle JDeveloper Projects中的jasper Report Viewer Composite的打印选项来打印jasper报表,而无需添加任何其他代码(默认情况下).

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).

推荐答案

在Eclipse RCP应用程序中制作Jasper Reports的最佳方法如下:

The best way for me to make my Jasper Reports in Eclipse RCP application was as follows :

  1. 首先用SWT/AWT复合材料和JRViewer(net.sf.jasperreports.view.JRViewer)替换ViewerComposite(即com.jasperassistant.designer.viewer.ViewerComposite.ViewerComposite).
  2. 将生成的JasperPrint文档设置到JRViewer对象上.
  3. 将JRViewer对象添加到此SWT/AWT组合的ContentPane中.
  4. 运行报告并检查打印并将报告数据导出为允许的格式,例如( .PDF, .ODT, .docx, .jrxml,. jasper, .xml, .html, .xls等);一切都会工作.
  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.

这的详细代码如下:

//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);

这篇关于如何使用其打印选项在Eclipse RCP中打印jasper报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆