eclipse - 如何使用其打印选项在 Eclipse RCP 中打印 jasper 报告?

标签 eclipse printing jasper-reports rcp

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

最佳答案

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

  • 首先用 SWT/AWT 复合和 JRViewer(net.sf.jasperreports.view.JRViewer)替换 ViewerComposite(即 com.jasperassistant.designer.viewer.ViewerComposite.ViewerComposite)。
  • 将生成的 JasperPrint 文档设置到 JRViewer 对象上。
  • 将 JRViewer 对象添加到此 SWT/AWT 组合的 ContentPane 中。
  • 运行报告并检查报告数据的打印和导出为允许的格式,即(.PDF、.ODT、.docx、.jrxml、.jasper、.xml、.html、.xls 等);一切都会好起来的。

  • 详细代码如下:

    //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 - 如何使用其打印选项在 Eclipse RCP 中打印 jasper 报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8487451/

    相关文章:

    java - 如何打印包含大量组件的 Java Swing UI?

    jasper-reports - 将几个相同的值字段组合到一个单元格中

    android - 如何从 sd 卡 android 获取所有音频文件

    java - 整个项目的语法突出显示已损坏

    Eclipse - 仅将待办事项限制为某些文件(或忽略项目中的整个文件夹)

    eclipse - 如何解锁 Eclipse 4.5 (Mars) 中的工具栏?

    python - 如何在 python 中打印 sqlite3 的输出

    php - tpcl(TEC Printer Command Language) [ESC]PC 左对齐

    JasperReports 中的 java.util.ConcurrentModificationException

    jasper-reports - 贾斯珀报告 : center current page number and total page number