How to print jasper report in Eclipse RCP using print option?

My question is: I have a ViewerComposite application in Eclipse RCP that displays the Jasper Report (* .jrxml) embedded in it. The report displayed in this ViewerComposite can be exported as PDF, RTF, XML, jrxml, HTML, CSV, etc. Everything is in order, except that I cannot print this report using the print option presented at the top of the ViewerComposite in the graphical interface. How to print reports using my default printer using the print option for the report viewer. Rem: I can print the jasper report using the option to print the jasper report compiler in Oracle JDeveloper projects without adding any codes (by default).

+4
source share
1 answer

The best way to do my Jasper reports in an Eclipse RCP application:

  • first replace ViewerComposite (i.e. com.jasperassistant.designer.viewer.ViewerComposite.ViewerComposite) with SWT / AWT and JRViewer (net.sf.jasperreports.view.JRViewer).
  • set the generated JasperPrint document to the JRViewer object.
  • Add a JRViewer object to the ContentPane of this SWT / AWT composite.
  • run the report and check the printing and export of the report data in the allowed formats (. PDF, .ODT, .docx, .jrxml, .jasper, .xml, .html, .xls, etc.); everything will work.

The data 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); 
+5
source

Source: https://habr.com/ru/post/1386071/


All Articles