Printing with an Eclipse RCP program

别等时光非礼了梦想. 提交于 2019-12-23 01:05:37

问题


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:


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



回答2:


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

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



来源:https://stackoverflow.com/questions/2521593/printing-with-an-eclipse-rcp-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!