views:

338

answers:

2

Hi,

I am looking for a good, standard way to generate "output" in my RCP programm and print it. This should work as it works on Windows, Mac OS and Linux with the standard print dialog.

I am aware of the Birt project, but I could not find any hints about how to implement it within a RCP programm and how to invoke the standard print dialog and how to pass the Birt generated report to the printer.

Happy for all hints.

+1  A: 

I believe the Birt project used to use IText. (now ITextPDF)

The other solution is to integrate Apache Fop in your RCP project. (see Apache FOP).
For that to work, it is advised to not implement a renderer but implement a IFDocumentHandler/IFPainter pair, as part of a new intermediate format (if that has been integrated to Fop, which I am not sure):

  • create a new Java project, decide on a package name and prepare two classes implementing IFDocumentHandler (document-level) and IFPainter (page-level).
    These interfaces are found in the package org.apache.fop.render.intermediate.
  • To register the new implementation, you need to define a MIME type (see also MimeConstants.java) and create a class extending AbstractIFDocumentHandlerMaker which serves as a factory class.
  • Then create a text file called META-INF/services/org.apache.fop.render.intermediate.IFDocumentHandler in which you write the fully qualified class name of that "maker" class.
  • One thing I may have to add (that is currently- missing) is a setIFDocumentHandlerOverride() method in FOUserAgent, so you can set up the output in an SWT window. The normal API is optimized for generating files.

The bug 23618 (fixed seven years later!) contains a small example of making a Printer Job, and the SWT FAQ has some interesting elements on Printer (vs. Display, DPI and Trim). This SWT snippet is quite clear too.
However, none of those examples are called through commands, even though you can define one easily) once you have a Handler (i.e. any class you wrote, able to open the print dialog) set up.

Note: be aware, when you are calling the Print Dialog Box, that only the very latest releases of Eclipse Helios 3.6 (namely the 3.6M5 of late January 2010) is able to remember the user selected options for all textual editors until the workbench is shutdown (that is:

  • Selected printer
  • Print to file
  • Printer preferences: These are printer specific options like paper size, page order orientation etc. )
VonC
Thanks, sounds like a very good answer. Just the link to my eclipse RCP program and the standard print dialog is unclear to me. And how is the output "moved" to the printer(queue).
Raven
Thanks again, but it seems like we are talking about 2 different things. I wanted to understand how to call and use a standard print dialog (using commands, not actions - since actions should be used anymore..) and then how to get the data passed to the printerqueue. Havent found tutorials about that yet.
Raven
@Raven: true, that was an old FAQ entry based on actions, which is "bad";) I have updated my answer with some elements on the topic, but without definitive answers though.
VonC
A: 

You might consider using SWT Paperclips. This made printing from my RCP application much, much easier.

http://code.google.com/p/swt-paperclips/

ksher