java rcp 打印,如何使用其打印选项在Eclipse RCP中打印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).

解决方案

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值