开发者

Printing with an Eclipse RCP program

开发者 https://www.devze.com 2022-12-25 04:19 出处:网络
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开发者_如何学C Windows, Mac OS and Linux with the standard print dialog.

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开发者_如何学C 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.


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


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号